Fix for #4136 connection to linux refused by using wrong Xauthority file

Solution:
1. Get file from sddm-greeter and startplasma-x11 (aka KDE) processes as well
2. Get users home dir from system instead of hard coded pattern /home/<user>
3. Prefer XAUTHORITY environment variable over Xorg -auth if available
This commit is contained in:
Awalon
2023-04-23 03:43:47 +02:00
parent 9cc09c620f
commit 028767da8b
3 changed files with 138 additions and 37 deletions

View File

@@ -322,7 +322,19 @@ fn patch(path: PathBuf) -> PathBuf {
.trim()
.to_owned();
if user != "root" {
return format!("/home/{user}").into();
let cmd = format!("getent passwd '{}' | awk -F':' '{{print $6}}'", user);
if let Ok(output) = std::process::Command::new(cmd).output() {
let home_dir = String::from_utf8_lossy(&output.stdout)
.to_string()
.trim()
.to_owned();
if home_dir.is_empty() {
return format!("/home/{user}").into();
} else {
log::info!("config::patch: got home dir from: {}", home_dir);
return home_dir.into();
}
}
}
}
}