From 127ab57d62539949be82ed330f41a9a53cbc79b5 Mon Sep 17 00:00:00 2001 From: fufesou Date: Thu, 30 Mar 2023 14:11:56 +0800 Subject: [PATCH] ignore 'gdm' on loginctl Signed-off-by: fufesou --- flutter/lib/models/model.dart | 6 ++--- libs/hbb_common/src/platform/linux.rs | 2 +- src/client.rs | 22 ++++++++-------- src/lang/en.rs | 2 +- src/platform/linux.rs | 10 ++++++++ src/platform/linux_desktop_manager.rs | 29 +++++++++++++-------- src/server/connection.rs | 36 ++++++++++++++++----------- src/ui/common.tis | 4 +-- src/ui/msgbox.tis | 24 +++++++++--------- 9 files changed, 80 insertions(+), 55 deletions(-) diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 7d1249906..77e1b8fbf 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -293,10 +293,10 @@ class FfiModel with ChangeNotifier { wrongPasswordDialog(id, dialogManager, type, title, text); } else if (type == 'input-password') { enterPasswordDialog(id, dialogManager); - } else if (type == 'xsession-login' || type == 'xsession-re-login') { + } else if (type == 'session-login' || type == 'session-re-login') { enterUserLoginDialog(id, dialogManager); - } else if (type == 'xsession-login-password' || - type == 'xsession-login-password') { + } else if (type == 'session-login-password' || + type == 'session-login-password') { enterUserLoginAndPasswordDialog(id, dialogManager); } else if (type == 'restarting') { showMsgBox(id, type, title, text, link, false, dialogManager, diff --git a/libs/hbb_common/src/platform/linux.rs b/libs/hbb_common/src/platform/linux.rs index 1d826ea97..cf1cf6da5 100644 --- a/libs/hbb_common/src/platform/linux.rs +++ b/libs/hbb_common/src/platform/linux.rs @@ -135,7 +135,7 @@ pub fn get_values_of_seat0_with_gdm_wayland(indices: &[usize]) -> Vec { fn _get_values_of_seat0(indices: &[usize], ignore_gdm_wayland: bool) -> Vec { if let Ok(output) = run_loginctl(None) { for line in String::from_utf8_lossy(&output.stdout).lines() { - if line.contains("seat0") { + if !line.contains("gdm") && line.contains("seat0") { if let Some(sid) = line.split_whitespace().next() { if is_active(sid) { if ignore_gdm_wayland { diff --git a/src/client.rs b/src/client.rs index f03cb0e55..3819ed382 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1927,34 +1927,34 @@ pub fn handle_login_error( lc.write().unwrap().password = Default::default(); interface.msgbox("re-input-password", err, "Do you want to enter again?", ""); true - } else if err == crate::server::LOGIN_MSG_XSESSION_NOT_READY { + } else if err == crate::server::LOGIN_MSG_DESKTOP_SESSION_NOT_READY { interface.msgbox( - "xsession-login", - "xsession is unready", + "session-login", + "session is unready", "Input linux user/password", "", ); true - } else if err == crate::server::LOGIN_MSG_XSESSION_FAILED { + } else if err == crate::server::LOGIN_MSG_DESKTOP_XSESSION_FAILED { interface.msgbox( - "xsession-re-login", + "session-re-login", "xsession username/password is wrong", "Do you want to enter again?", "", ); true - } else if err == crate::server::LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_EMPTY { + } else if err == crate::server::LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_EMPTY { interface.msgbox( - "xsession-login-password", - "xsession is unready", + "session-login-password", + "session is unready", "Input connection password and linux user/password", "", ); true - } else if err == crate::server::LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_WRONG { + } else if err == crate::server::LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_WRONG { interface.msgbox( - "xsession-login-re-password", - "xsession is unready and password is wrong", + "session-login-re-password", + "session is unready and password is wrong", "Do you want to enter again?", "", ); diff --git a/src/lang/en.rs b/src/lang/en.rs index 2ea65b05f..11ad719ab 100644 --- a/src/lang/en.rs +++ b/src/lang/en.rs @@ -56,7 +56,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("show_monitors_tip", "Show monitors in toolbar."), ("enter_rustdesk_passwd_tip", "Enter RustDesk password"), ("remember_rustdesk_passwd_tip", "Remember RustDesk password"), - ("login_linux_tip", "You need to login to remote Linux account to enable a X desktop session"), + ("login_linux_tip", "Remote desktop is unready. Please \n 1. Login on remote side and then try again\n 2. Or input remote account to login and start a X desktop session"), ("verify_rustdesk_password_tip", "Veryfy RustDesk password"), ("remember_account_tip", "Remember this account"), ("remember_password_tip", "Remember password"), diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 8c4a68848..fa83fdc1f 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -21,6 +21,9 @@ use std::{ type Xdo = *const c_void; +pub const ENV_DESKTOP_PROTOCAL_WAYLAND: &str = "wayland"; +pub const ENV_DESKTOP_PROTOCAL_X11: &str = "x11"; + pub const PA_SAMPLE_RATE: u32 = 48000; static mut UNMODIFIED: bool = true; @@ -930,6 +933,8 @@ mod desktop { if !self.sid.is_empty() && is_active(&self.sid) { return; } + + println!("REMOVE ME ================================== desktop: refresh"); let seat0_values = get_values_of_seat0(&[0, 1, 2]); if seat0_values[0].is_empty() { *self = Self::default(); @@ -950,6 +955,11 @@ mod desktop { self.get_display(); self.get_xauth(); self.set_is_subprocess(); + + println!( + "REMOVE ME ================================== desktop: {:?}", + self + ); } } } diff --git a/src/platform/linux_desktop_manager.rs b/src/platform/linux_desktop_manager.rs index a957e045e..f1ddec58e 100644 --- a/src/platform/linux_desktop_manager.rs +++ b/src/platform/linux_desktop_manager.rs @@ -22,7 +22,7 @@ lazy_static::lazy_static! { #[derive(Debug)] struct DesktopManager { - x11_username: String, + seat0_username: String, child_username: String, child_exit: Arc, is_child_running: Arc, @@ -61,8 +61,8 @@ pub fn stop_xdesktop() { pub fn try_start_x_session(username: &str, password: &str) -> ResultType<(String, bool)> { let mut desktop_manager = DESKTOP_MANAGER.lock().unwrap(); if let Some(desktop_manager) = &mut (*desktop_manager) { - if !desktop_manager.x11_username.is_empty() { - return Ok((desktop_manager.x11_username.clone(), true)); + if !desktop_manager.seat0_username.is_empty() { + return Ok((desktop_manager.seat0_username.clone(), true)); } let _ = desktop_manager.try_start_x_session(username, password)?; @@ -76,7 +76,7 @@ pub fn try_start_x_session(username: &str, password: &str) -> ResultType<(String desktop_manager.is_running(), )) } else { - bail!(crate::server::LOGIN_MSG_XDESKTOP_NOT_INITED); + bail!(crate::server::LOGIN_MSG_DESKTOP_NOT_INITED); } } @@ -86,14 +86,14 @@ pub fn is_headless() -> bool { .lock() .unwrap() .as_ref() - .map_or(false, |manager| manager.x11_username.is_empty()) + .map_or(false, |manager| manager.seat0_username.is_empty()) } pub fn get_username() -> String { match &*DESKTOP_MANAGER.lock().unwrap() { Some(manager) => { - if !manager.x11_username.is_empty() { - manager.x11_username.clone() + if !manager.seat0_username.is_empty() { + manager.seat0_username.clone() } else { if manager.is_running() && !manager.child_username.is_empty() { manager.child_username.clone() @@ -118,16 +118,23 @@ impl DesktopManager { } pub fn new() -> Self { - let mut x11_username = "".to_owned(); + let mut seat0_username = "".to_owned(); let seat0_values = get_values_of_seat0(&[0, 1, 2]); + println!( + "REMOVE ME ================================== DesktopManager: {:?}", + &seat0_values + ); if !seat0_values[0].is_empty() { - if "x11" == get_display_server_of_session(&seat0_values[1]) { - x11_username = seat0_values[2].clone(); + let display_server = get_display_server_of_session(&seat0_values[1]); + if display_server == ENV_DESKTOP_PROTOCAL_X11 + || display_server == ENV_DESKTOP_PROTOCAL_WAYLAND + { + seat0_username = seat0_values[2].clone(); } } Self { - x11_username, + seat0_username, child_username: "".to_owned(), child_exit: Arc::new(AtomicBool::new(true)), is_child_running: Arc::new(AtomicBool::new(false)), diff --git a/src/server/connection.rs b/src/server/connection.rs index ee4bdda35..f9c64378e 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -59,12 +59,14 @@ lazy_static::lazy_static! { pub static CLICK_TIME: AtomicI64 = AtomicI64::new(0); pub static MOUSE_MOVE_TIME: AtomicI64 = AtomicI64::new(0); -pub const LOGIN_MSG_XDESKTOP_NOT_INITED: &str = "xdesktop env is not inited"; -pub const LOGIN_MSG_XSESSION_NOT_READY: &str = "xsession unready"; -pub const LOGIN_MSG_XSESSION_FAILED: &str = "xsession failed"; -pub const LOGIN_MSG_XSESSION_ANOTHER_USER_READTY: &str = "xsession another user login"; -pub const LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_EMPTY: &str = "xsession unready, password empty"; -pub const LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_WRONG: &str = "xsession unready, password wrong"; +pub const LOGIN_MSG_DESKTOP_NOT_INITED: &str = "Desktop env is not inited"; +pub const LOGIN_MSG_DESKTOP_SESSION_NOT_READY: &str = "Desktop session unready"; +pub const LOGIN_MSG_DESKTOP_XSESSION_FAILED: &str = "Desktop xsession failed"; +pub const LOGIN_MSG_DESKTOP_SESSION_ANOTHER_USER: &str = "Desktop session another user login"; +pub const LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_EMPTY: &str = + "Desktop session unready, password empty"; +pub const LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_WRONG: &str = + "Desktop session unready, password wrong"; pub const LOGIN_MSG_PASSWORD_EMPTY: &str = "Empty Password"; pub const LOGIN_MSG_PASSWORD_WRONG: &str = "Wrong Password"; pub const LOGIN_MSG_OFFLINE: &str = "Offline"; @@ -1081,27 +1083,33 @@ impl Connection { if _username.is_empty() { let username = linux_desktop_manager::get_username(); if username.is_empty() { - LOGIN_MSG_XSESSION_NOT_READY + LOGIN_MSG_DESKTOP_SESSION_NOT_READY } else { "" } .to_owned() } else { + let username = linux_desktop_manager::get_username(); + if username == _username { + // No need to verify password here. + return "".to_owned(); + } + match linux_desktop_manager::try_start_x_session(_username, _passsword) { Ok((username, x11_ready)) => { if x11_ready { if _username != username { - LOGIN_MSG_XSESSION_ANOTHER_USER_READTY.to_owned() + LOGIN_MSG_DESKTOP_SESSION_ANOTHER_USER.to_owned() } else { "".to_owned() } } else { - LOGIN_MSG_XSESSION_NOT_READY.to_owned() + LOGIN_MSG_DESKTOP_SESSION_NOT_READY.to_owned() } } Err(e) => { log::error!("Failed to start xsession {}", e); - LOGIN_MSG_XSESSION_FAILED.to_owned() + LOGIN_MSG_DESKTOP_XSESSION_FAILED.to_owned() } } } @@ -1278,8 +1286,8 @@ impl Connection { Some(os_login) => Self::try_start_desktop(&os_login.username, &os_login.password), None => Self::try_start_desktop("", ""), }; - // If err is LOGIN_MSG_XSESSION_NOT_READY, just keep this msg and go on checking password. - if !desktop_err.is_empty() && desktop_err != LOGIN_MSG_XSESSION_NOT_READY { + // If err is LOGIN_MSG_DESKTOP_SESSION_NOT_READY, just keep this msg and go on checking password. + if !desktop_err.is_empty() && desktop_err != LOGIN_MSG_DESKTOP_SESSION_NOT_READY { self.send_login_error(desktop_err).await; return true; } @@ -1315,7 +1323,7 @@ impl Connection { if desktop_err.is_empty() { self.try_start_cm(lr.my_id, lr.my_name, false); } else { - self.send_login_error(LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_EMPTY) + self.send_login_error(LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_EMPTY) .await; } } else { @@ -1362,7 +1370,7 @@ impl Connection { self.send_login_error(LOGIN_MSG_PASSWORD_WRONG).await; self.try_start_cm(lr.my_id, lr.my_name, false); } else { - self.send_login_error(LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_WRONG) + self.send_login_error(LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_WRONG) .await; } } else { diff --git a/src/ui/common.tis b/src/ui/common.tis index ef6d215aa..92e704052 100644 --- a/src/ui/common.tis +++ b/src/ui/common.tis @@ -262,7 +262,7 @@ function msgbox(type, title, content, link="", callback=null, height=180, width= else msgbox("connecting", "Connecting...", "Logging in..."); } }; - } else if (type == "xsession-login" || type == "xsession-re-login") { + } else if (type == "session-login" || type == "session-re-login") { callback = function (res) { if (!res) { view.close(); @@ -274,7 +274,7 @@ function msgbox(type, title, content, link="", callback=null, height=180, width= else msgbox("connecting", "Connecting...", "Logging in..."); } }; - } else if (type.indexOf("xsession-login") >= 0) { + } else if (type.indexOf("session-login") >= 0) { callback = function (res) { if (!res) { view.close(); diff --git a/src/ui/msgbox.tis b/src/ui/msgbox.tis index d9a311452..2099a8e7b 100644 --- a/src/ui/msgbox.tis +++ b/src/ui/msgbox.tis @@ -32,7 +32,7 @@ class MsgboxComponent: Reactor.Component { } function getIcon(color) { - if (this.type == "input-password" || this.type == "xsession-login" || this.type == "xsession-login-password") { + if (this.type == "input-password" || this.type == "session-login" || this.type == "session-login-password") { return ; } if (this.type == "connecting") { @@ -41,7 +41,7 @@ class MsgboxComponent: Reactor.Component { if (this.type == "success") { return ; } - if (this.type.indexOf("error") >= 0 || this.type == "re-input-password" || this.type == "xsession-re-login" || this.type == "xsession-login-re-password") { + if (this.type.indexOf("error") >= 0 || this.type == "re-input-password" || this.type == "session-re-login" || this.type == "session-login-re-password") { return ; } return null; @@ -81,9 +81,9 @@ class MsgboxComponent: Reactor.Component { function getContent() { if (this.type == "input-password") { return this.getInputPasswordContent(); - } else if (this.type == "xsession-login") { + } else if (this.type == "session-login") { return this.getInputUserPasswordContent(); - } else if (this.type == "xsession-login-password") { + } else if (this.type == "session-login-password") { return this.getXsessionPasswordContent(); } else if (this.type == "custom-os-password") { var ts = this.auto_login ? { checked: true } : {}; @@ -96,13 +96,13 @@ class MsgboxComponent: Reactor.Component { } function getColor() { - if (this.type == "input-password" || this.type == "custom-os-password" || this.type == "xsession-login" || this.type == "xsession-login-password") { + if (this.type == "input-password" || this.type == "custom-os-password" || this.type == "session-login" || this.type == "session-login-password") { return "#AD448E"; } if (this.type == "success") { return "#32bea6"; } - if (this.type.indexOf("error") >= 0 || this.type == "re-input-password" || this.type == "xsession-re-login" || this.type == "xsession-login-re-password") { + if (this.type.indexOf("error") >= 0 || this.type == "re-input-password" || this.type == "session-re-login" || this.type == "session-login-re-password") { return "#e04f5f"; } return "#2C8CFF"; @@ -202,13 +202,13 @@ class MsgboxComponent: Reactor.Component { this.update(); return; } - if (this.type == "xsession-re-login") { - this.type = "xsession-login"; + if (this.type == "session-re-login") { + this.type = "session-login"; this.update(); return; } - if (this.type == "xsession-login-re-password") { - this.type = "xsession-login-password"; + if (this.type == "session-login-re-password") { + this.type = "session-login-password"; this.update(); return; } @@ -273,14 +273,14 @@ class MsgboxComponent: Reactor.Component { return; } } - if (this.type == "xsession-login") { + if (this.type == "session-login") { values.osusername = (values.osusername || "").trim(); values.ospassword = (values.ospassword || "").trim(); if (!values.osusername || !values.ospassword) { return; } } - if (this.type == "xsession-login-password") { + if (this.type == "session-login-password") { values.password = (values.password || "").trim(); values.osusername = (values.osusername || "").trim(); values.ospassword = (values.ospassword || "").trim();