mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-12-04 15:46:07 +00:00
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:
1 parent
0d1cc89828
commit
742e507ca6
3 files changed
+63
-2
No files matched your search
@@ -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 = "0" OR FIREWALLRULES ~= "N")" />
|
||||
<SetProperty Action="NormalizeFirewallRulesDisabled" Id="FIREWALLRULES" Value="0" After="NormalizeFirewallRulesEnabled" Sequence="first" Condition="FIREWALLRULES ~= "N"" />
|
||||
|
||||
<!-- 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>
|
||||
|
||||
|
||||
@@ -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="outgoing")"/>
|
||||
|
||||
|
||||
@@ -1563,6 +1563,31 @@ pub fn remove_meta_toml_cmd(is_msi: bool, path: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_firewall_rules(
|
||||
args: impl Iterator<Item = OsString>,
|
||||
read_saved: impl FnOnce() -> io::Result<String>,
|
||||
) -> &'static str {
|
||||
let value = args
|
||||
.filter_map(|arg| {
|
||||
let arg = arg.to_string_lossy();
|
||||
let (key, value) = arg.split_once('=')?;
|
||||
key.eq_ignore_ascii_case("FIREWALLRULES")
|
||||
.then(|| value.to_owned())
|
||||
})
|
||||
.last()
|
||||
.map(Ok)
|
||||
.unwrap_or_else(read_saved);
|
||||
let error = match value.as_deref() {
|
||||
Ok("0" | "N" | "n") => return "0",
|
||||
Ok("1" | "Y" | "y") => return "1",
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => return "1",
|
||||
Err(error) => error.to_string(),
|
||||
_ => "FIREWALLRULES must be 0, 1, Y, or N".to_owned(),
|
||||
};
|
||||
log::warn!("Failed to resolve FIREWALLRULES: {error}; using the default value 1 and continuing installation");
|
||||
"1"
|
||||
}
|
||||
|
||||
fn get_after_install(
|
||||
exe: &str,
|
||||
reg_value_start_menu_shortcuts: Option<String>,
|
||||
@@ -1571,6 +1596,12 @@ fn get_after_install(
|
||||
) -> String {
|
||||
let app_name = crate::get_app_name();
|
||||
let ext = app_name.to_lowercase();
|
||||
// Resolve the saved choice before the reinstall script deletes its registry key.
|
||||
let firewall_rules = resolve_firewall_rules(std::env::args_os().skip(1), || {
|
||||
RegKey::predef(HKEY_CLASSES_ROOT)
|
||||
.open_subkey(format!(".{ext}"))?
|
||||
.get_value("FIREWALLRULES")
|
||||
});
|
||||
let nested_exe = escape_nested_cmd_ampersands(exe);
|
||||
|
||||
// reg delete HKEY_CURRENT_USER\Software\Classes for
|
||||
@@ -1618,8 +1649,12 @@ fn get_after_install(
|
||||
reg add HKEY_CLASSES_ROOT\\{ext}\\shell\\open /f
|
||||
reg add HKEY_CLASSES_ROOT\\{ext}\\shell\\open\\command /f
|
||||
reg add HKEY_CLASSES_ROOT\\{ext}\\shell\\open\\command /f /ve /t REG_SZ /d \"\\\"{nested_exe}\\\" \\\"%%1\\\"\"
|
||||
reg add HKEY_CLASSES_ROOT\\.{ext} /f /v FIREWALLRULES /t REG_SZ /d \"{firewall_rules}\"
|
||||
if not \"%errorlevel%\"==\"0\" echo WARNING: Failed to save FIREWALLRULES. Continuing installation; future upgrades may use the default. 1>&2
|
||||
if \"{firewall_rules}\"==\"1\" (
|
||||
netsh advfirewall firewall add rule name=\"{app_name} Service\" dir=out action=allow program=\"{exe}\" enable=yes
|
||||
netsh advfirewall firewall add rule name=\"{app_name} Service\" dir=in action=allow program=\"{exe}\" enable=yes
|
||||
)
|
||||
{create_service}
|
||||
reg add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /f /v SoftwareSASGeneration /t REG_DWORD /d 1
|
||||
", create_service=get_create_service(&exe))
|
||||
|
||||
Reference in new issue
Block a user