refactor handle_login_error to avoid dead lock, and recover pr #2602

This commit is contained in:
rustdesk
2022-12-27 11:42:48 +08:00
parent c5feb95509
commit 7d5876f7b8
4 changed files with 57 additions and 36 deletions

View File

@@ -892,6 +892,8 @@ pub struct LoginConfigHandler {
pub supported_encoding: Option<(bool, bool)>,
pub restarting_remote_device: bool,
pub force_relay: bool,
pub direct: Option<bool>,
pub received: bool,
}
impl Deref for LoginConfigHandler {
@@ -929,6 +931,8 @@ impl LoginConfigHandler {
self.supported_encoding = None;
self.restarting_remote_device = false;
self.force_relay = !self.get_option("force-always-relay").is_empty();
self.direct = None;
self.received = false;
}
/// Check if the client should auto login.
@@ -1338,32 +1342,6 @@ impl LoginConfigHandler {
}
}
/// Handle login error.
/// Return true if the password is wrong, return false if there's an actual error.
pub fn handle_login_error(&mut self, err: &str, interface: &impl Interface) -> bool {
if err == "Wrong Password" {
self.password = Default::default();
interface.msgbox("re-input-password", err, "Do you want to enter again?", "");
true
} else if err == "No Password Access" {
self.password = Default::default();
interface.msgbox(
"wait-remote-accept-nook",
"Prompt",
"Please wait for the remote side to accept your session request...",
"",
);
true
} else {
if err.contains(SCRAP_X11_REQUIRED) {
interface.msgbox("error", "Login Error", err, SCRAP_X11_REF_URL);
} else {
interface.msgbox("error", "Login Error", err, "");
}
false
}
}
/// Get user name.
/// Return the name of the given peer. If the peer has no name, return the name in the config.
///
@@ -1726,6 +1704,36 @@ fn _input_os_password(p: String, activate: bool, interface: impl Interface) {
interface.send(Data::Message(msg_out));
}
/// Handle login error.
/// Return true if the password is wrong, return false if there's an actual error.
pub fn handle_login_error(
lc: Arc<RwLock<LoginConfigHandler>>,
err: &str,
interface: &impl Interface,
) -> bool {
if err == "Wrong Password" {
lc.write().unwrap().password = Default::default();
interface.msgbox("re-input-password", err, "Do you want to enter again?", "");
true
} else if err == "No Password Access" {
lc.write().unwrap().password = Default::default();
interface.msgbox(
"wait-remote-accept-nook",
"Prompt",
"Please wait for the remote side to accept your session request...",
"",
);
true
} else {
if err.contains(SCRAP_X11_REQUIRED) {
interface.msgbox("error", "Login Error", err, SCRAP_X11_REF_URL);
} else {
interface.msgbox("error", "Login Error", err, "");
}
false
}
}
/// Handle hash message sent by peer.
/// Hash will be used for login.
///
@@ -1815,6 +1823,7 @@ pub trait Interface: Send + Clone + 'static + Sized {
fn handle_login_error(&mut self, err: &str) -> bool;
fn handle_peer_info(&mut self, pi: PeerInfo);
fn set_force_relay(&mut self, direct: bool, received: bool);
fn set_connection_info(&mut self, direct: bool, received: bool);
fn is_file_transfer(&self) -> bool;
fn is_port_forward(&self) -> bool;
fn is_rdp(&self) -> bool;
@@ -1990,11 +1999,10 @@ lazy_static::lazy_static! {
/// * `title` - The title of the message.
/// * `text` - The text of the message.
#[inline]
pub fn check_if_retry(msgtype: &str, title: &str, text: &str) -> bool {
pub fn check_if_retry(msgtype: &str, title: &str, text: &str, retry_for_relay: bool) -> bool {
msgtype == "error"
&& title == "Connection Error"
&& (text.contains("10054")
|| text.contains("104")
&& ((text.contains("10054") || text.contains("104")) && retry_for_relay
|| (!text.to_lowercase().contains("offline")
&& !text.to_lowercase().contains("exist")
&& !text.to_lowercase().contains("handshake")