Compare commits

..
Author SHA1 Message Date
rustdeskandClaude Opus 5.5 071d9b1eff fix(linux): stop using the window in onWindowClose once GTK destroyed it
On Linux, GTK destroys the window on a close request unless prevent-close
is on. When the main window is the last active one, onActiveWindowChanged()
turns prevent-close off and calls close(), yet onWindowClose() still went
on to hide() the destroyed window, and the close event that close() emits
re-entered onWindowClose() to save the frame through isMaximized(). The cm
and install windows never turn prevent-close on, so their window is always
gone by the time onWindowClose() runs.

With window_manager before cf4aef05 those calls segfaulted in
gtk_window_is_maximized; since then they fail with an unhandled
PlatformException(window_destroyed). Return early in both places instead.
Other platforms and sub windows keep the old path.

Fixes #16512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WS1HTjp6UQuG43KEcQPq1R
2026-10-15 15:01:40 +08:00
3 changed files with 23 additions and 271 deletions
+2 -28
View File
@@ -267,13 +267,7 @@ async fn race_transports_prefer_webrtc<'a, T: 'a>(
}
}
match others_err.take() {
// Report one error, as `select_ok` does: the UI matches and translates
// the text whole (e.g. the offline auto-retry), and both legs often
// carry the same rendezvous refusal anyway.
Some(oe) => {
log::warn!("fallback leg also failed: {}", oe);
return Err(e);
}
Some(oe) => bail!("WebRTC failed: {}; fallback failed: {}", e, oe),
None if others_fut.is_none() => bail!("WebRTC failed: {}", e),
None => webrtc_err = Some(e),
}
@@ -314,10 +308,7 @@ async fn race_transports_prefer_webrtc<'a, T: 'a>(
// it before failing the connection.
Some(we) => match held.take() {
Some(conn) => return Ok(conn),
None => {
log::warn!("WebRTC leg also failed: {}", we);
return Err(e);
}
None => bail!("WebRTC failed: {}; fallback failed: {}", we, e),
},
None if webrtc_fut.is_none() => match held.take() {
Some(conn) => return Ok(conn),
@@ -5718,23 +5709,6 @@ mod webrtc_race_tests {
assert_eq!(got, "ipv6");
assert!(start.elapsed() < Duration::from_secs(5));
}
// Both legs get the same rendezvous refusal; the UI needs the text verbatim, e.g. the
// offline auto-retry matches it whole. Either leg may fail last.
#[tokio::test]
async fn same_failure_on_both_legs_reported_once() {
for (webrtc_ms, fallback_ms) in [(10, 20), (20, 10)] {
let err = race_transports_prefer_webrtc(
err_after(webrtc_ms, "Remote desktop is offline"),
vec![err_after(fallback_ms, "Remote desktop is offline")],
60_000,
NOT_P2P,
)
.await
.unwrap_err();
assert_eq!(err.to_string(), "Remote desktop is offline");
}
}
}
#[cfg(test)]
+21 -58
View File
@@ -1,16 +1,12 @@
mod directory;
use super::{
installer_shell::{
get_system_executable, path_for_cmd_assignment, path_for_cmd_environment,
run_elevated_and_wait, trusted_install_environment,
BATCH_SHORTCUT_DECODE_FAILURE_EXIT_CODE, CMD_RELATIVE_PATH,
WIN7_SHELL_EXECUTE_MAX_PARAMETER_CHARS,
},
validate_install_app_name, ResultType,
};
use hbb_common::{
anyhow::anyhow,
bail, log,
sha2::{Digest, Sha256},
};
@@ -103,8 +99,10 @@ fn verified_install_bootstrap(
runner_directory: &Path,
) -> ResultType<String> {
let source = path_for_cmd_assignment(&script.path)?;
let directory = path_for_cmd_assignment(runner_directory)?;
let runner = runner_directory.join("install.bat");
let runner = runner_directory.join(format!(
"rustdesk_install_{}.bat",
uuid::Uuid::new_v4().simple()
));
let runner = path_for_cmd_assignment(&runner)?;
let cmd_path = get_system_executable(CMD_RELATIVE_PATH)?;
let certutil_path = get_system_executable(CERTUTIL_RELATIVE_PATH)?;
@@ -115,13 +113,13 @@ fn verified_install_bootstrap(
// Short names preserve headroom under the Windows 7 ShellExecuteExW 2,048
// UTF-16-character parameter limit. Paths are stored with delayed expansion
// disabled, then expanded indirectly so literal `!` survives: S=source,
// R=runner, Q=cmd.exe, H=certutil.exe, F=findstr.exe, D=directory, E=exit code.
// R=runner, Q=cmd.exe, H=certutil.exe, F=findstr.exe, C=created flag, E=exit code.
Ok(format!(
"setlocal DisableDelayedExpansion & set \"S={source}\" & set \"R={runner}\" & \
set \"Q={cmd}\" & set \"H={certutil}\" & set \"F={findstr}\" & \
set \"ERRORLEVEL=\" & set \"D={directory}\" & set \"E=0\" & setlocal EnableDelayedExpansion & \
set \"C=0\" & set \"E=0\" & setlocal EnableDelayedExpansion & \
if exist \"!R!\" (set \"E={INSTALL_HANDOFF_RUNNER_EXISTS_EXIT_CODE}\") else (\
copy /Y \"!S!\" \"!R!\" > nul || \
set \"C=1\" & copy /Y \"!S!\" \"!R!\" > nul || \
(set \"E={INSTALL_HANDOFF_COPY_FAILURE_EXIT_CODE}\") & \
if \"!E!\"==\"0\" (\"!H!\" -hashfile \"!R!\" SHA256 > \"!R!.hash\" || \
set \"E={INSTALL_HANDOFF_HASH_FAILURE_EXIT_CODE}\") & \
@@ -129,51 +127,26 @@ fn verified_install_bootstrap(
set \"E={INSTALL_HANDOFF_HASH_MISMATCH_EXIT_CODE}\") & \
if \"!E!\"==\"0\" (\"!Q!\" /D /E:ON /V:OFF /C \"\"!R!\"\" & \
set \"E=!errorlevel!\")) & \
rd /s /q \"!D!\" > nul 2>&1 & exit /b !E!",
if \"!C!\"==\"1\" (rd /s /q \"!R!.dir\" > nul 2>&1 & \
del /f /q \"!R!\" \"!R!.*\" > nul 2>&1) & exit /b !E!",
install_hash_pattern(&script.expected_hash),
))
}
fn verified_install_parameters(
script: &InstallCommandScript,
directory: &Path,
) -> ResultType<String> {
let parameters = format!(
fn verified_install_parameters(script: &InstallCommandScript) -> ResultType<String> {
let system_directory = get_system_executable("")?;
Ok(format!(
"/D /E:ON /V:ON /C {}",
verified_install_bootstrap(script, directory)?
);
let length = parameters.encode_utf16().count();
if length >= WIN7_SHELL_EXECUTE_MAX_PARAMETER_CHARS {
bail!("Elevated command is too long: {length} UTF-16 characters");
}
Ok(parameters)
verified_install_bootstrap(script, &system_directory)?
))
}
pub(super) fn run_cmds(cmds: String, show: bool, tip: &str) -> ResultType<()> {
validate_install_app_name(&crate::get_app_name())?;
let script = write_install_script(cmds)?;
let cmd_path = get_system_executable(CMD_RELATIVE_PATH)?;
let directory = directory::path()?;
let parameters = verified_install_parameters(&script, &directory)?;
directory::create(&directory)?;
let exit_code = run_elevated_and_wait(&cmd_path, &parameters, show).map_err(|err| {
anyhow!(
"Installer handoff failed; protected directory may remain at {}: {err}",
directory.display()
)
})?;
// Cleanup must not change the result of an installation that already ran.
match fs::symlink_metadata(&directory) {
Ok(_) => log::warn!(
"Protected installer directory may remain at {}",
directory.display()
),
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
Err(err) => log::warn!(
"Protected installer directory may remain at {}: {err}",
directory.display()
),
}
let parameters = verified_install_parameters(&script)?;
let exit_code = run_elevated_and_wait(&cmd_path, &parameters, show)?;
if exit_code != 0 {
bail!(
"{tip} failed with elevated exit code {exit_code}: {}",
@@ -235,7 +208,7 @@ mod tests {
.expect("install script should be created");
let bootstrap = verified_install_bootstrap(&script, &runner_dir)
.expect("native verifier bootstrap should be generated");
assert_native_handoff_structure(&script, &shortcut_commands, &runner_dir);
assert_native_handoff_structure(&script, &shortcut_commands, &bootstrap);
let output = run_install_bootstrap_for_test(&bootstrap);
assert!(
@@ -245,25 +218,15 @@ mod tests {
);
assert!(marker.exists(), "verified install script must execute");
std::fs::remove_file(&marker).expect("test marker should be removed");
assert!(
!runner_dir.exists(),
"protected runner directory must be removed"
);
std::fs::create_dir(&runner_dir).expect("runner directory should be created");
assert_replaced_install_script_is_rejected(&script, &runner_dir, &marker);
assert!(
!runner_dir.exists(),
"failed handoff directory must be removed"
);
std::fs::remove_dir(runner_dir).expect("runner directory should be empty");
}
fn assert_native_handoff_structure(
script: &InstallCommandScript,
shortcut_commands: &str,
runner_dir: &Path,
bootstrap: &str,
) {
let bootstrap = verified_install_bootstrap(script, runner_dir)
.expect("native verifier bootstrap should be generated");
assert!(shortcut_commands.contains("certutil"));
assert!(shortcut_commands.contains("-decode"));
assert!(!shortcut_commands.to_ascii_lowercase().contains("cscript"));
@@ -277,8 +240,8 @@ mod tests {
.collect::<Vec<_>>()
.join(" *");
assert!(bootstrap.contains(&format!("/R /I /X /C:\"{win7_hash_pattern}\"")));
let parameters = verified_install_parameters(script, runner_dir)
.expect("elevated parameters should be generated");
let parameters =
verified_install_parameters(script).expect("elevated parameters should be generated");
assert!(bootstrap.contains("certutil.exe"));
assert!(bootstrap.contains("findstr.exe"));
assert!(!bootstrap.to_ascii_lowercase().contains("powershell"));
@@ -1,185 +0,0 @@
use super::super::{
installer_shell::{get_system_executable, path_for_cmd_environment},
wide_string,
};
use hbb_common::{anyhow::anyhow, bail, ResultType};
use std::{
fs, mem,
os::windows::fs::MetadataExt,
path::{Path, PathBuf},
};
use windows::{
core::{w, PCWSTR},
Win32::{
Foundation::{LocalFree, HLOCAL},
Security::{
Authorization::{
ConvertStringSecurityDescriptorToSecurityDescriptorW, SDDL_REVISION_1,
},
PSECURITY_DESCRIPTOR, SECURITY_ATTRIBUTES,
},
Storage::FileSystem::{CreateDirectoryW, FILE_ATTRIBUTE_REPARSE_POINT},
},
};
pub(super) fn path() -> ResultType<PathBuf> {
let system = get_system_executable("")?;
let windows = system
.parent()
.ok_or_else(|| anyhow!("System directory has no parent"))?;
let temporary = windows.join("Temp");
for parent in temporary.ancestors() {
let metadata = fs::symlink_metadata(parent).map_err(|err| {
anyhow!(
"Failed to inspect installer temporary parent {}: {err}",
parent.display()
)
})?;
if !metadata.is_dir() || metadata.file_attributes() & FILE_ATTRIBUTE_REPARSE_POINT.0 != 0 {
bail!(
"Installer temporary parent is not a regular directory: {}",
parent.display()
);
}
}
Ok(temporary.join(format!(
"rustdesk-install-{}",
uuid::Uuid::new_v4().simple()
)))
}
pub(super) fn create(path: &Path) -> ResultType<()> {
let wide_path = wide_string(path_for_cmd_environment(path)?);
let mut descriptor = PSECURITY_DESCRIPTOR::default();
// OWNER RIGHTS removes the ordinary creator's implicit WRITE_DAC permission.
// The owner can inspect the ACL, but only Administrators/SYSTEM can modify contents.
// https://learn.microsoft.com/windows-server/identity/ad-ds/manage/understand-special-identities-groups#owner-rights
unsafe {
ConvertStringSecurityDescriptorToSecurityDescriptorW(
w!("D:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;RC;;;OW)"),
SDDL_REVISION_1,
&mut descriptor,
None,
)?;
}
let attributes = SECURITY_ATTRIBUTES {
nLength: mem::size_of::<SECURITY_ATTRIBUTES>() as u32,
lpSecurityDescriptor: descriptor.0,
bInheritHandle: false.into(),
};
let result = unsafe { CreateDirectoryW(PCWSTR(wide_path.as_ptr()), Some(&attributes)) };
unsafe { LocalFree(Some(HLOCAL(descriptor.0))) };
result.map_err(|err| {
anyhow!(
"Failed to create protected installer directory {}: {err}",
path.display()
)
})
}
#[cfg(test)]
mod tests {
use super::*;
use winapi::um::winnt::MAXIMUM_ALLOWED;
use windows::{
core::{Owned, BOOL},
Win32::{
Foundation::HANDLE,
Security::{
AccessCheck,
Authorization::{GetNamedSecurityInfoW, SE_FILE_OBJECT},
DuplicateToken, SecurityImpersonation, DACL_SECURITY_INFORMATION, GENERIC_MAPPING,
GROUP_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION, PRIVILEGE_SET,
TOKEN_DUPLICATE, TOKEN_QUERY,
},
Storage::FileSystem::{
FILE_ALL_ACCESS, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ, FILE_GENERIC_WRITE,
READ_CONTROL,
},
System::Threading::{GetCurrentProcess, OpenProcessToken},
},
};
#[test]
fn protected_directory_enforces_creator_permissions() {
let elevated =
super::super::super::is_elevated(None).expect("creator elevation should be available");
// The user-owned parent allows cleanup through DELETE_CHILD. AccessCheck
// below checks the child's DACL, not that separate parent permission.
let directory = std::env::temp_dir().join(format!(
"rustdesk_installer_acl_{}",
uuid::Uuid::new_v4().simple()
));
create(&directory).expect("production directory creation should succeed");
let access = creator_directory_access(&directory);
fs::remove_dir(&directory).expect("test directory should be removed");
let expected = if elevated {
FILE_ALL_ACCESS
} else {
READ_CONTROL
};
assert_eq!(
access.expect("the created directory's access should be checked"),
(true, expected.0),
"only elevated administrators may modify the protected directory"
);
}
fn creator_directory_access(path: &Path) -> ResultType<(bool, u32)> {
let wide_path = wide_string(path_for_cmd_environment(path)?);
let mut descriptor = PSECURITY_DESCRIPTOR::default();
unsafe {
GetNamedSecurityInfoW(
PCWSTR(wide_path.as_ptr()),
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
None,
None,
None,
None,
&mut descriptor,
)
.ok()?;
}
let _descriptor = unsafe { Owned::new(HLOCAL(descriptor.0)) };
let token = creator_impersonation_token()?;
let mapping = GENERIC_MAPPING {
GenericRead: FILE_GENERIC_READ.0,
GenericWrite: FILE_GENERIC_WRITE.0,
GenericExecute: FILE_GENERIC_EXECUTE.0,
GenericAll: FILE_ALL_ACCESS.0,
};
let mut privileges = PRIVILEGE_SET::default();
let mut privilege_size = mem::size_of::<PRIVILEGE_SET>() as u32;
let mut granted = 0;
let mut allowed = BOOL::default();
unsafe {
AccessCheck(
descriptor,
*token,
MAXIMUM_ALLOWED,
&mapping,
Some(&mut privileges),
&mut privilege_size,
&mut granted,
&mut allowed,
)?;
}
Ok((allowed.as_bool(), granted))
}
fn creator_impersonation_token() -> ResultType<Owned<HANDLE>> {
let mut token = HANDLE::default();
unsafe {
OpenProcessToken(
GetCurrentProcess(),
TOKEN_QUERY | TOKEN_DUPLICATE,
&mut token,
)?
};
let token = unsafe { Owned::new(token) };
let mut impersonation = HANDLE::default();
unsafe { DuplicateToken(*token, SecurityImpersonation, &mut impersonation)? };
Ok(unsafe { Owned::new(impersonation) })
}
}