Fix for #4136 connection to linux refused by using wrong Xauthority file.
This PR handles comments of 2nd review for initial PR #4165. Reduced number of info/log messages
This commit is contained in:
parent
9bf058bb32
commit
82c44d71f9
@ -329,7 +329,6 @@ fn patch(path: PathBuf) -> PathBuf {
|
|||||||
.trim()
|
.trim()
|
||||||
.to_owned();
|
.to_owned();
|
||||||
if !home_dir.is_empty() {
|
if !home_dir.is_empty() {
|
||||||
log::info!("config::patch: got home dir from: {}", home_dir);
|
|
||||||
return home_dir.into();
|
return home_dir.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -863,22 +863,18 @@ mod desktop {
|
|||||||
"ps -u {} -f | grep 'Xorg' | grep -v 'grep'",
|
"ps -u {} -f | grep 'Xorg' | grep -v 'grep'",
|
||||||
&self.uid
|
&self.uid
|
||||||
)) {
|
)) {
|
||||||
log::debug!("extracting xauth file for Xorg running with uid: {}", self.uid);
|
|
||||||
for line in output.lines() {
|
for line in output.lines() {
|
||||||
let mut auth_found = false;
|
let mut auth_found = false;
|
||||||
|
|
||||||
for v in line.split_whitespace() {
|
for v in line.split_whitespace() {
|
||||||
if v == "-auth" {
|
if v == "-auth" {
|
||||||
log::debug!("- auth parameter detected");
|
|
||||||
auth_found = true;
|
auth_found = true;
|
||||||
} else if auth_found {
|
} else if auth_found {
|
||||||
if std::path::Path::new(v).is_absolute()
|
if std::path::Path::new(v).is_absolute()
|
||||||
&& std::path::Path::new(v).exists() {
|
&& std::path::Path::new(v).exists() {
|
||||||
|
|
||||||
self.xauth = v.to_string();
|
self.xauth = v.to_string();
|
||||||
log::debug!("+ auth file with absolute path detected: {}", self.xauth);
|
|
||||||
} else {
|
} else {
|
||||||
log::debug!("- auth file with relative path detected: {}", v);
|
|
||||||
if let Some(pid) = line.split_whitespace().nth(1) {
|
if let Some(pid) = line.split_whitespace().nth(1) {
|
||||||
let mut base_dir: String = String::from("/home"); // default pattern
|
let mut base_dir: String = String::from("/home"); // default pattern
|
||||||
let home_dir = get_env_from_pid("HOME", pid);
|
let home_dir = get_env_from_pid("HOME", pid);
|
||||||
@ -891,7 +887,6 @@ mod desktop {
|
|||||||
}
|
}
|
||||||
if Path::new(&base_dir).exists() {
|
if Path::new(&base_dir).exists() {
|
||||||
self.xauth = format!("{}/{}", base_dir, v);
|
self.xauth = format!("{}/{}", base_dir, v);
|
||||||
log::debug!("+ auth file with home path added: {}", self.xauth);
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// unreachable!
|
// unreachable!
|
||||||
@ -902,11 +897,9 @@ mod desktop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::debug!("- auth file detected by Xorg: {}", self.xauth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_xauth(&mut self) {
|
fn get_xauth(&mut self) {
|
||||||
log::debug!("guessing xauth file...");
|
|
||||||
// try by direct access to window manager process by name
|
// try by direct access to window manager process by name
|
||||||
let display_envs = vec![
|
let display_envs = vec![
|
||||||
GNOME_SESSION_BINARY,
|
GNOME_SESSION_BINARY,
|
||||||
@ -916,10 +909,7 @@ mod desktop {
|
|||||||
];
|
];
|
||||||
for diplay_env in display_envs {
|
for diplay_env in display_envs {
|
||||||
self.xauth = get_env_tries("XAUTHORITY", &self.uid, diplay_env, 10);
|
self.xauth = get_env_tries("XAUTHORITY", &self.uid, diplay_env, 10);
|
||||||
if self.xauth.is_empty() {
|
if !self.xauth.is_empty() {
|
||||||
log::debug!("- nothing for {} {} (GNOME)", self.uid, diplay_env);
|
|
||||||
} else {
|
|
||||||
log::debug!("+ found {} for {} {} (GNOME)", self.xauth, self.uid, diplay_env);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -933,13 +923,11 @@ mod desktop {
|
|||||||
if self.xauth.is_empty() {
|
if self.xauth.is_empty() {
|
||||||
let gdm = format!("/run/user/{}/gdm/Xauthority", self.uid);
|
let gdm = format!("/run/user/{}/gdm/Xauthority", self.uid);
|
||||||
self.xauth = if std::path::Path::new(&gdm).exists() {
|
self.xauth = if std::path::Path::new(&gdm).exists() {
|
||||||
log::debug!("+ found gdm for {}: {}", self.uid, gdm);
|
|
||||||
gdm
|
gdm
|
||||||
} else {
|
} else {
|
||||||
let username = &self.username;
|
let username = &self.username;
|
||||||
match get_user_home_by_name(username) {
|
match get_user_home_by_name(username) {
|
||||||
None => {
|
None => {
|
||||||
log::debug!("- user home dir not detected: {}", username);
|
|
||||||
if username == "root" {
|
if username == "root" {
|
||||||
format!("/{}/.Xauthority", username)
|
format!("/{}/.Xauthority", username)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user