From 742e507ca66cec7858462ab912d2550628a94de1 Mon Sep 17 00:00:00 2001 From: fufesou Date: Thu, 19 Nov 2026 18:03:34 +0800 Subject: [PATCH] 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 * 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 * 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 * refactor(windows): simplify installer firewall option Signed-off-by: fufesou * refactor(windows): retain legacy firewall installer flow Signed-off-by: fufesou * fix(msi): default unknown firewall values to enabled Signed-off-by: fufesou * 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 --------- Signed-off-by: fufesou --- res/msi/Package/Components/Regs.wxs | 26 ++++++++++++++++++ res/msi/Package/Components/RustDesk.wxs | 4 +-- src/platform/windows.rs | 35 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/res/msi/Package/Components/Regs.wxs b/res/msi/Package/Components/Regs.wxs index 25988f4a8..ecc85adfc 100644 --- a/res/msi/Package/Components/Regs.wxs +++ b/res/msi/Package/Components/Regs.wxs @@ -3,6 +3,31 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -26,6 +51,7 @@ + diff --git a/res/msi/Package/Components/RustDesk.wxs b/res/msi/Package/Components/RustDesk.wxs index 3041c6099..c847ef575 100644 --- a/res/msi/Package/Components/RustDesk.wxs +++ b/res/msi/Package/Components/RustDesk.wxs @@ -79,8 +79,8 @@ - - + + diff --git a/src/platform/windows.rs b/src/platform/windows.rs index a3acdca60..03d2b5eea 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1563,6 +1563,31 @@ pub fn remove_meta_toml_cmd(is_msi: bool, path: &str) -> String { } } +fn resolve_firewall_rules( + args: impl Iterator, + read_saved: impl FnOnce() -> io::Result, +) -> &'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, @@ -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))