diff --git a/src/client.rs b/src/client.rs index 40b3542b3..a60251980 100644 --- a/src/client.rs +++ b/src/client.rs @@ -91,7 +91,7 @@ pub const LOGIN_MSG_PASSWORD_WRONG: &str = "Wrong Password"; pub const LOGIN_MSG_NO_PASSWORD_ACCESS: &str = "No Password Access"; pub const LOGIN_MSG_OFFLINE: &str = "Offline"; #[cfg(target_os = "linux")] -pub const LOGIN_SCREEN_WAYLAND: &str = "Wayland login screen"; +pub const LOGIN_SCREEN_WAYLAND: &str = "Wayland login screen is not supported"; #[cfg(target_os = "linux")] pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version."; #[cfg(target_os = "linux")] diff --git a/src/platform/linux.rs b/src/platform/linux.rs index e254af12e..f553d63ba 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -1,5 +1,8 @@ use super::{CursorData, ResultType}; use desktop::Desktop; +#[cfg(all(feature = "linux_headless"))] +#[cfg(not(any(feature = "flatpak", feature = "appimage")))] +use hbb_common::config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS; pub use hbb_common::platform::linux::*; use hbb_common::{ allow_err, bail, @@ -9,9 +12,6 @@ use hbb_common::{ message_proto::Resolution, regex::{Captures, Regex}, }; -#[cfg(all(feature = "linux_headless"))] -#[cfg(not(any(feature = "flatpak", feature = "appimage")))] -use hbb_common::config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS; use std::{ cell::RefCell, io::Write, @@ -439,13 +439,21 @@ fn get_cm() -> bool { } pub fn is_login_wayland() -> bool { - if let Ok(contents) = std::fs::read_to_string("/etc/gdm3/custom.conf") { - contents.contains("#WaylandEnable=false") || contents.contains("WaylandEnable=true") - } else if let Ok(contents) = std::fs::read_to_string("/etc/gdm/custom.conf") { - contents.contains("#WaylandEnable=false") || contents.contains("WaylandEnable=true") - } else { - false + let files = ["/etc/gdm3/custom.conf", "/etc/gdm/custom.conf"]; + match ( + Regex::new(r"# *WaylandEnable *= *false"), + Regex::new(r"WaylandEnable *= *true"), + ) { + (Ok(pat1), Ok(pat2)) => { + for file in files { + if let Ok(contents) = std::fs::read_to_string(file) { + return pat1.is_match(&contents) || pat2.is_match(&contents); + } + } + } + _ => {} } + false } #[inline] diff --git a/src/platform/linux_desktop_manager.rs b/src/platform/linux_desktop_manager.rs index 1382fa2ed..b7caa527c 100644 --- a/src/platform/linux_desktop_manager.rs +++ b/src/platform/linux_desktop_manager.rs @@ -109,7 +109,7 @@ pub fn try_start_desktop(_username: &str, _passsword: &str) -> String { // No need to verify password here. return "".to_owned(); } - if username.is_empty() { + if !username.is_empty() { // Another user is logged in. No need to start a new xsession. return "".to_owned(); } diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rs index 97a6d91d8..924c0c709 100644 --- a/src/rendezvous_mediator.rs +++ b/src/rendezvous_mediator.rs @@ -73,11 +73,10 @@ impl RendezvousMediator { allow_err!(super::lan::start_listening()); }); } + // It is ok to run xdesktop manager when the headless function is not allowed. #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] - if crate::platform::is_headless_allowed() { - crate::platform::linux_desktop_manager::start_xdesktop(); - } + crate::platform::linux_desktop_manager::start_xdesktop(); loop { Config::reset_online(); if Config::get_option("stop-service").is_empty() { diff --git a/src/server/connection.rs b/src/server/connection.rs index 30a87cd80..7e0f39809 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1386,6 +1386,12 @@ impl Connection { #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let is_headless_allowed = crate::platform::is_headless_allowed(); + #[cfg(any( + feature = "flatpak", + feature = "appimage", + not(all(target_os = "linux", feature = "linux_headless")) + ))] + let is_headless_allowed = false; #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let desktop_err = if is_headless_allowed { @@ -1406,20 +1412,10 @@ impl Connection { #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let wait_ipc_timeout = 10_000; - #[cfg(all(target_os = "linux", feature = "linux_headless"))] - #[cfg(not(any(feature = "flatpak", feature = "appimage")))] - let is_headless_proc = is_headless_allowed; - #[cfg(any( - feature = "flatpak", - feature = "appimage", - not(all(target_os = "linux", feature = "linux_headless")) - ))] - let is_headless_proc = false; - // If err is LOGIN_MSG_DESKTOP_SESSION_NOT_READY, just keep this msg and go on checking password. #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] - if is_headless_proc + if is_headless_allowed && !desktop_err.is_empty() && desktop_err != crate::client::LOGIN_MSG_DESKTOP_SESSION_NOT_READY { @@ -1453,7 +1449,7 @@ impl Connection { } else if self.is_recent_session() { #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] - if is_headless_proc { + if is_headless_allowed { if desktop_err.is_empty() { if is_headless { self.tx_desktop_ready.send(()).await.ok(); @@ -1469,7 +1465,7 @@ impl Connection { self.send_login_error(desktop_err).await; } } - if !is_headless_proc { + if !is_headless_allowed { self.try_start_cm(lr.my_id, lr.my_name, true); self.send_logon_response().await; if self.port_forward_socket.is_some() { @@ -1479,7 +1475,7 @@ impl Connection { } else if lr.password.is_empty() { #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] - if is_headless_proc { + if is_headless_allowed { if desktop_err.is_empty() { self.try_start_cm(lr.my_id.clone(), lr.my_name.clone(), false); } else { @@ -1489,7 +1485,7 @@ impl Connection { .await; } } - if !is_headless_proc { + if !is_headless_allowed { self.try_start_cm(lr.my_id, lr.my_name, false); } } else { @@ -1532,7 +1528,7 @@ impl Connection { .insert(self.ip.clone(), failure); #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] - if is_headless_proc { + if is_headless_allowed { if desktop_err.is_empty() { self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG) .await; @@ -1544,7 +1540,7 @@ impl Connection { .await; } } - if !is_headless_proc { + if !is_headless_allowed { self.send_login_error(crate::client::LOGIN_MSG_PASSWORD_WRONG) .await; self.try_start_cm(lr.my_id, lr.my_name, false); @@ -1555,7 +1551,7 @@ impl Connection { } #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] - if is_headless_proc { + if is_headless_allowed { if desktop_err.is_empty() { if is_headless { self.tx_desktop_ready.send(()).await.ok(); @@ -1571,7 +1567,7 @@ impl Connection { self.send_login_error(desktop_err).await; } } - if !is_headless_proc { + if !is_headless_allowed { self.send_logon_response().await; self.try_start_cm(lr.my_id, lr.my_name, true); if self.port_forward_socket.is_some() {