ignore 'gdm' on loginctl

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-03-30 14:11:56 +08:00
parent 8aa5f3a2a7
commit 127ab57d62
9 changed files with 80 additions and 55 deletions

View File

@ -293,10 +293,10 @@ class FfiModel with ChangeNotifier {
wrongPasswordDialog(id, dialogManager, type, title, text); wrongPasswordDialog(id, dialogManager, type, title, text);
} else if (type == 'input-password') { } else if (type == 'input-password') {
enterPasswordDialog(id, dialogManager); enterPasswordDialog(id, dialogManager);
} else if (type == 'xsession-login' || type == 'xsession-re-login') { } else if (type == 'session-login' || type == 'session-re-login') {
enterUserLoginDialog(id, dialogManager); enterUserLoginDialog(id, dialogManager);
} else if (type == 'xsession-login-password' || } else if (type == 'session-login-password' ||
type == 'xsession-login-password') { type == 'session-login-password') {
enterUserLoginAndPasswordDialog(id, dialogManager); enterUserLoginAndPasswordDialog(id, dialogManager);
} else if (type == 'restarting') { } else if (type == 'restarting') {
showMsgBox(id, type, title, text, link, false, dialogManager, showMsgBox(id, type, title, text, link, false, dialogManager,

View File

@ -135,7 +135,7 @@ pub fn get_values_of_seat0_with_gdm_wayland(indices: &[usize]) -> Vec<String> {
fn _get_values_of_seat0(indices: &[usize], ignore_gdm_wayland: bool) -> Vec<String> { fn _get_values_of_seat0(indices: &[usize], ignore_gdm_wayland: bool) -> Vec<String> {
if let Ok(output) = run_loginctl(None) { if let Ok(output) = run_loginctl(None) {
for line in String::from_utf8_lossy(&output.stdout).lines() { 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 let Some(sid) = line.split_whitespace().next() {
if is_active(sid) { if is_active(sid) {
if ignore_gdm_wayland { if ignore_gdm_wayland {

View File

@ -1927,34 +1927,34 @@ pub fn handle_login_error(
lc.write().unwrap().password = Default::default(); lc.write().unwrap().password = Default::default();
interface.msgbox("re-input-password", err, "Do you want to enter again?", ""); interface.msgbox("re-input-password", err, "Do you want to enter again?", "");
true true
} else if err == crate::server::LOGIN_MSG_XSESSION_NOT_READY { } else if err == crate::server::LOGIN_MSG_DESKTOP_SESSION_NOT_READY {
interface.msgbox( interface.msgbox(
"xsession-login", "session-login",
"xsession is unready", "session is unready",
"Input linux user/password", "Input linux user/password",
"", "",
); );
true true
} else if err == crate::server::LOGIN_MSG_XSESSION_FAILED { } else if err == crate::server::LOGIN_MSG_DESKTOP_XSESSION_FAILED {
interface.msgbox( interface.msgbox(
"xsession-re-login", "session-re-login",
"xsession username/password is wrong", "xsession username/password is wrong",
"Do you want to enter again?", "Do you want to enter again?",
"", "",
); );
true 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( interface.msgbox(
"xsession-login-password", "session-login-password",
"xsession is unready", "session is unready",
"Input connection password and linux user/password", "Input connection password and linux user/password",
"", "",
); );
true 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( interface.msgbox(
"xsession-login-re-password", "session-login-re-password",
"xsession is unready and password is wrong", "session is unready and password is wrong",
"Do you want to enter again?", "Do you want to enter again?",
"", "",
); );

View File

@ -56,7 +56,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("show_monitors_tip", "Show monitors in toolbar."), ("show_monitors_tip", "Show monitors in toolbar."),
("enter_rustdesk_passwd_tip", "Enter RustDesk password"), ("enter_rustdesk_passwd_tip", "Enter RustDesk password"),
("remember_rustdesk_passwd_tip", "Remember 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"), ("verify_rustdesk_password_tip", "Veryfy RustDesk password"),
("remember_account_tip", "Remember this account"), ("remember_account_tip", "Remember this account"),
("remember_password_tip", "Remember password"), ("remember_password_tip", "Remember password"),

View File

@ -21,6 +21,9 @@ use std::{
type Xdo = *const c_void; 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; pub const PA_SAMPLE_RATE: u32 = 48000;
static mut UNMODIFIED: bool = true; static mut UNMODIFIED: bool = true;
@ -930,6 +933,8 @@ mod desktop {
if !self.sid.is_empty() && is_active(&self.sid) { if !self.sid.is_empty() && is_active(&self.sid) {
return; return;
} }
println!("REMOVE ME ================================== desktop: refresh");
let seat0_values = get_values_of_seat0(&[0, 1, 2]); let seat0_values = get_values_of_seat0(&[0, 1, 2]);
if seat0_values[0].is_empty() { if seat0_values[0].is_empty() {
*self = Self::default(); *self = Self::default();
@ -950,6 +955,11 @@ mod desktop {
self.get_display(); self.get_display();
self.get_xauth(); self.get_xauth();
self.set_is_subprocess(); self.set_is_subprocess();
println!(
"REMOVE ME ================================== desktop: {:?}",
self
);
} }
} }
} }

View File

@ -22,7 +22,7 @@ lazy_static::lazy_static! {
#[derive(Debug)] #[derive(Debug)]
struct DesktopManager { struct DesktopManager {
x11_username: String, seat0_username: String,
child_username: String, child_username: String,
child_exit: Arc<AtomicBool>, child_exit: Arc<AtomicBool>,
is_child_running: Arc<AtomicBool>, is_child_running: Arc<AtomicBool>,
@ -61,8 +61,8 @@ pub fn stop_xdesktop() {
pub fn try_start_x_session(username: &str, password: &str) -> ResultType<(String, bool)> { pub fn try_start_x_session(username: &str, password: &str) -> ResultType<(String, bool)> {
let mut desktop_manager = DESKTOP_MANAGER.lock().unwrap(); let mut desktop_manager = DESKTOP_MANAGER.lock().unwrap();
if let Some(desktop_manager) = &mut (*desktop_manager) { if let Some(desktop_manager) = &mut (*desktop_manager) {
if !desktop_manager.x11_username.is_empty() { if !desktop_manager.seat0_username.is_empty() {
return Ok((desktop_manager.x11_username.clone(), true)); return Ok((desktop_manager.seat0_username.clone(), true));
} }
let _ = desktop_manager.try_start_x_session(username, password)?; 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(), desktop_manager.is_running(),
)) ))
} else { } 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() .lock()
.unwrap() .unwrap()
.as_ref() .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 { pub fn get_username() -> String {
match &*DESKTOP_MANAGER.lock().unwrap() { match &*DESKTOP_MANAGER.lock().unwrap() {
Some(manager) => { Some(manager) => {
if !manager.x11_username.is_empty() { if !manager.seat0_username.is_empty() {
manager.x11_username.clone() manager.seat0_username.clone()
} else { } else {
if manager.is_running() && !manager.child_username.is_empty() { if manager.is_running() && !manager.child_username.is_empty() {
manager.child_username.clone() manager.child_username.clone()
@ -118,16 +118,23 @@ impl DesktopManager {
} }
pub fn new() -> Self { 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]); let seat0_values = get_values_of_seat0(&[0, 1, 2]);
println!(
"REMOVE ME ================================== DesktopManager: {:?}",
&seat0_values
);
if !seat0_values[0].is_empty() { if !seat0_values[0].is_empty() {
if "x11" == get_display_server_of_session(&seat0_values[1]) { let display_server = get_display_server_of_session(&seat0_values[1]);
x11_username = seat0_values[2].clone(); if display_server == ENV_DESKTOP_PROTOCAL_X11
|| display_server == ENV_DESKTOP_PROTOCAL_WAYLAND
{
seat0_username = seat0_values[2].clone();
} }
} }
Self { Self {
x11_username, seat0_username,
child_username: "".to_owned(), child_username: "".to_owned(),
child_exit: Arc::new(AtomicBool::new(true)), child_exit: Arc::new(AtomicBool::new(true)),
is_child_running: Arc::new(AtomicBool::new(false)), is_child_running: Arc::new(AtomicBool::new(false)),

View File

@ -59,12 +59,14 @@ lazy_static::lazy_static! {
pub static CLICK_TIME: AtomicI64 = AtomicI64::new(0); pub static CLICK_TIME: AtomicI64 = AtomicI64::new(0);
pub static MOUSE_MOVE_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_DESKTOP_NOT_INITED: &str = "Desktop env is not inited";
pub const LOGIN_MSG_XSESSION_NOT_READY: &str = "xsession unready"; pub const LOGIN_MSG_DESKTOP_SESSION_NOT_READY: &str = "Desktop session unready";
pub const LOGIN_MSG_XSESSION_FAILED: &str = "xsession failed"; pub const LOGIN_MSG_DESKTOP_XSESSION_FAILED: &str = "Desktop xsession failed";
pub const LOGIN_MSG_XSESSION_ANOTHER_USER_READTY: &str = "xsession another user login"; pub const LOGIN_MSG_DESKTOP_SESSION_ANOTHER_USER: &str = "Desktop session another user login";
pub const LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_EMPTY: &str = "xsession unready, password empty"; pub const LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_EMPTY: &str =
pub const LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_WRONG: &str = "xsession unready, password wrong"; "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_EMPTY: &str = "Empty Password";
pub const LOGIN_MSG_PASSWORD_WRONG: &str = "Wrong Password"; pub const LOGIN_MSG_PASSWORD_WRONG: &str = "Wrong Password";
pub const LOGIN_MSG_OFFLINE: &str = "Offline"; pub const LOGIN_MSG_OFFLINE: &str = "Offline";
@ -1081,27 +1083,33 @@ impl Connection {
if _username.is_empty() { if _username.is_empty() {
let username = linux_desktop_manager::get_username(); let username = linux_desktop_manager::get_username();
if username.is_empty() { if username.is_empty() {
LOGIN_MSG_XSESSION_NOT_READY LOGIN_MSG_DESKTOP_SESSION_NOT_READY
} else { } else {
"" ""
} }
.to_owned() .to_owned()
} else { } 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) { match linux_desktop_manager::try_start_x_session(_username, _passsword) {
Ok((username, x11_ready)) => { Ok((username, x11_ready)) => {
if x11_ready { if x11_ready {
if _username != username { if _username != username {
LOGIN_MSG_XSESSION_ANOTHER_USER_READTY.to_owned() LOGIN_MSG_DESKTOP_SESSION_ANOTHER_USER.to_owned()
} else { } else {
"".to_owned() "".to_owned()
} }
} else { } else {
LOGIN_MSG_XSESSION_NOT_READY.to_owned() LOGIN_MSG_DESKTOP_SESSION_NOT_READY.to_owned()
} }
} }
Err(e) => { Err(e) => {
log::error!("Failed to start xsession {}", 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), Some(os_login) => Self::try_start_desktop(&os_login.username, &os_login.password),
None => Self::try_start_desktop("", ""), None => Self::try_start_desktop("", ""),
}; };
// If err is LOGIN_MSG_XSESSION_NOT_READY, just keep this msg and go on checking password. // 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_XSESSION_NOT_READY { if !desktop_err.is_empty() && desktop_err != LOGIN_MSG_DESKTOP_SESSION_NOT_READY {
self.send_login_error(desktop_err).await; self.send_login_error(desktop_err).await;
return true; return true;
} }
@ -1315,7 +1323,7 @@ impl Connection {
if desktop_err.is_empty() { if desktop_err.is_empty() {
self.try_start_cm(lr.my_id, lr.my_name, false); self.try_start_cm(lr.my_id, lr.my_name, false);
} else { } 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; .await;
} }
} else { } else {
@ -1362,7 +1370,7 @@ impl Connection {
self.send_login_error(LOGIN_MSG_PASSWORD_WRONG).await; self.send_login_error(LOGIN_MSG_PASSWORD_WRONG).await;
self.try_start_cm(lr.my_id, lr.my_name, false); self.try_start_cm(lr.my_id, lr.my_name, false);
} else { } 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; .await;
} }
} else { } else {

View File

@ -262,7 +262,7 @@ function msgbox(type, title, content, link="", callback=null, height=180, width=
else msgbox("connecting", "Connecting...", "Logging in..."); 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) { callback = function (res) {
if (!res) { if (!res) {
view.close(); view.close();
@ -274,7 +274,7 @@ function msgbox(type, title, content, link="", callback=null, height=180, width=
else msgbox("connecting", "Connecting...", "Logging in..."); else msgbox("connecting", "Connecting...", "Logging in...");
} }
}; };
} else if (type.indexOf("xsession-login") >= 0) { } else if (type.indexOf("session-login") >= 0) {
callback = function (res) { callback = function (res) {
if (!res) { if (!res) {
view.close(); view.close();

View File

@ -32,7 +32,7 @@ class MsgboxComponent: Reactor.Component {
} }
function getIcon(color) { 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 <svg viewBox="0 0 505 505"><circle cx="252.5" cy="252.5" r="252.5" fill={color}/><path d="M271.9 246.1c29.2 17.5 67.6 13.6 92.7-11.5 29.7-29.7 29.7-77.8 0-107.4s-77.8-29.7-107.4 0c-25.1 25.1-29 63.5-11.5 92.7L118.1 347.4l26.2 26.2 26.4 26.4 10.6-10.6-10.1-10.1 9.7-9.7 10.1 10.1 10.6-10.6-10.1-10 9.7-9.7 10.1 10.1 10.6-10.6-26.4-26.3 76.4-76.5z" fill="#fff"/><circle cx="337.4" cy="154.4" r="17.7" fill={color}/></svg>; return <svg viewBox="0 0 505 505"><circle cx="252.5" cy="252.5" r="252.5" fill={color}/><path d="M271.9 246.1c29.2 17.5 67.6 13.6 92.7-11.5 29.7-29.7 29.7-77.8 0-107.4s-77.8-29.7-107.4 0c-25.1 25.1-29 63.5-11.5 92.7L118.1 347.4l26.2 26.2 26.4 26.4 10.6-10.6-10.1-10.1 9.7-9.7 10.1 10.1 10.6-10.6-10.1-10 9.7-9.7 10.1 10.1 10.6-10.6-26.4-26.3 76.4-76.5z" fill="#fff"/><circle cx="337.4" cy="154.4" r="17.7" fill={color}/></svg>;
} }
if (this.type == "connecting") { if (this.type == "connecting") {
@ -41,7 +41,7 @@ class MsgboxComponent: Reactor.Component {
if (this.type == "success") { if (this.type == "success") {
return <svg viewBox="0 0 512 512"><circle cx="256" cy="256" r="256" fill={color} /><path fill="#fff" d="M235.472 392.08l-121.04-94.296 34.416-44.168 74.328 57.904 122.672-177.016 46.032 31.888z"/></svg>; return <svg viewBox="0 0 512 512"><circle cx="256" cy="256" r="256" fill={color} /><path fill="#fff" d="M235.472 392.08l-121.04-94.296 34.416-44.168 74.328 57.904 122.672-177.016 46.032 31.888z"/></svg>;
} }
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 <svg viewBox="0 0 512 512"><ellipse cx="256" cy="256" rx="256" ry="255.832" fill={color}/><g fill="#fff"><path d="M376.812 337.18l-39.592 39.593-201.998-201.999 39.592-39.592z"/><path d="M376.818 174.825L174.819 376.824l-39.592-39.592 201.999-201.999z"/></g></svg>; return <svg viewBox="0 0 512 512"><ellipse cx="256" cy="256" rx="256" ry="255.832" fill={color}/><g fill="#fff"><path d="M376.812 337.18l-39.592 39.593-201.998-201.999 39.592-39.592z"/><path d="M376.818 174.825L174.819 376.824l-39.592-39.592 201.999-201.999z"/></g></svg>;
} }
return null; return null;
@ -81,9 +81,9 @@ class MsgboxComponent: Reactor.Component {
function getContent() { function getContent() {
if (this.type == "input-password") { if (this.type == "input-password") {
return this.getInputPasswordContent(); return this.getInputPasswordContent();
} else if (this.type == "xsession-login") { } else if (this.type == "session-login") {
return this.getInputUserPasswordContent(); return this.getInputUserPasswordContent();
} else if (this.type == "xsession-login-password") { } else if (this.type == "session-login-password") {
return this.getXsessionPasswordContent(); return this.getXsessionPasswordContent();
} else if (this.type == "custom-os-password") { } else if (this.type == "custom-os-password") {
var ts = this.auto_login ? { checked: true } : {}; var ts = this.auto_login ? { checked: true } : {};
@ -96,13 +96,13 @@ class MsgboxComponent: Reactor.Component {
} }
function getColor() { 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"; return "#AD448E";
} }
if (this.type == "success") { if (this.type == "success") {
return "#32bea6"; 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 "#e04f5f";
} }
return "#2C8CFF"; return "#2C8CFF";
@ -202,13 +202,13 @@ class MsgboxComponent: Reactor.Component {
this.update(); this.update();
return; return;
} }
if (this.type == "xsession-re-login") { if (this.type == "session-re-login") {
this.type = "xsession-login"; this.type = "session-login";
this.update(); this.update();
return; return;
} }
if (this.type == "xsession-login-re-password") { if (this.type == "session-login-re-password") {
this.type = "xsession-login-password"; this.type = "session-login-password";
this.update(); this.update();
return; return;
} }
@ -273,14 +273,14 @@ class MsgboxComponent: Reactor.Component {
return; return;
} }
} }
if (this.type == "xsession-login") { if (this.type == "session-login") {
values.osusername = (values.osusername || "").trim(); values.osusername = (values.osusername || "").trim();
values.ospassword = (values.ospassword || "").trim(); values.ospassword = (values.ospassword || "").trim();
if (!values.osusername || !values.ospassword) { if (!values.osusername || !values.ospassword) {
return; return;
} }
} }
if (this.type == "xsession-login-password") { if (this.type == "session-login-password") {
values.password = (values.password || "").trim(); values.password = (values.password || "").trim();
values.osusername = (values.osusername || "").trim(); values.osusername = (values.osusername || "").trim();
values.ospassword = (values.ospassword || "").trim(); values.ospassword = (values.ospassword || "").trim();