From c944d6093d0487bd6a2a995a6e3f031c8dab86a8 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 29 Mar 2023 20:25:41 +0800 Subject: [PATCH] virtual display, linux, debug Signed-off-by: fufesou --- flutter/lib/models/model.dart | 4 +- libs/hbb_common/src/platform/mod.rs | 2 +- src/server/connection.rs | 85 +++++++++++++++++++++++------ 3 files changed, 72 insertions(+), 19 deletions(-) diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 155956c74..470bb47c3 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -294,10 +294,10 @@ class FfiModel with ChangeNotifier { } else if (type == 'input-password') { enterPasswordDialog(id, dialogManager); } else if (type == 'xsession-login' || type == 'xsession-re-login') { - // to-do + enterUserLoginDialog(id, dialogManager); } else if (type == 'xsession-login-password' || type == 'xsession-login-password') { - // to-do + enterUserLoginAndPasswordDialog(id, dialogManager); } else if (type == 'restarting') { showMsgBox(id, type, title, text, link, false, dialogManager, hasCancel: false); diff --git a/libs/hbb_common/src/platform/mod.rs b/libs/hbb_common/src/platform/mod.rs index f4a1122e5..c37c8aaf5 100644 --- a/libs/hbb_common/src/platform/mod.rs +++ b/libs/hbb_common/src/platform/mod.rs @@ -57,6 +57,6 @@ where { unsafe { GLOBAL_CALLBACK = Some(Box::new(callback)); - // libc::signal(libc::SIGSEGV, breakdown_signal_handler as _); + libc::signal(libc::SIGSEGV, breakdown_signal_handler as _); } } diff --git a/src/server/connection.rs b/src/server/connection.rs index 6bbbffefc..2f86ca5f0 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1285,16 +1285,11 @@ impl Connection { } else if password::approve_mode() == ApproveMode::Click || password::approve_mode() == ApproveMode::Both && !password::has_valid_password() { - if desktop_err.is_empty() { - self.try_start_cm(lr.my_id, lr.my_name, false); - if hbb_common::get_version_number(&lr.version) - >= hbb_common::get_version_number("1.2.0") - { - self.send_login_error("No Password Access").await; - } - } else { - self.send_login_error(LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_EMPTY) - .await; + self.try_start_cm(lr.my_id, lr.my_name, false); + if hbb_common::get_version_number(&lr.version) + >= hbb_common::get_version_number("1.2.0") + { + self.send_login_error("No Password Access").await; } return true; } else if password::approve_mode() == ApproveMode::Password @@ -1312,15 +1307,73 @@ impl Connection { } else { self.send_login_error(desktop_err).await; } - } else { + } else if lr.password.is_empty() { if desktop_err.is_empty() { - self.send_logon_response().await; - self.try_start_cm(lr.my_id, lr.my_name, true); - if self.port_forward_socket.is_some() { - return false; + self.try_start_cm(lr.my_id, lr.my_name, false); + } else { + self.send_login_error(LOGIN_MSG_XSESSION_NOT_READY_PASSWORD_EMPTY) + .await; + } + } else { + let mut failure = LOGIN_FAILURES + .lock() + .unwrap() + .get(&self.ip) + .map(|x| x.clone()) + .unwrap_or((0, 0, 0)); + let time = (get_time() / 60_000) as i32; + if failure.2 > 30 { + self.send_login_error("Too many wrong password attempts") + .await; + Self::post_alarm_audit( + AlarmAuditType::ManyWrongPassword, + true, + json!({ + "ip":self.ip, + }), + ); + } else if time == failure.0 && failure.1 > 6 { + self.send_login_error("Please try 1 minute later").await; + Self::post_alarm_audit( + AlarmAuditType::FrequentAttempt, + true, + json!({ + "ip":self.ip, + }), + ); + } else if !self.validate_password() { + if failure.0 == time { + failure.1 += 1; + failure.2 += 1; + } else { + failure.0 = time; + failure.1 = 1; + failure.2 += 1; + } + LOGIN_FAILURES + .lock() + .unwrap() + .insert(self.ip.clone(), failure); + if desktop_err.is_empty() { + 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) + .await; } } else { - self.send_login_error(desktop_err).await; + if failure.0 != 0 { + LOGIN_FAILURES.lock().unwrap().remove(&self.ip); + } + if desktop_err.is_empty() { + self.send_logon_response().await; + self.try_start_cm(lr.my_id, lr.my_name, true); + if self.port_forward_socket.is_some() { + return false; + } + } else { + self.send_login_error(desktop_err).await; + } } } } else if let Some(message::Union::TestDelay(t)) = msg.union {