Skip to content

Commit

Permalink
OPTION_ONE_WAY_CLIPBOARD_REDIRECTION,
Browse files Browse the repository at this point in the history
        OPTION_ENABLE_CLIPBOARD_INIT_SYNC,
        OPTION_ALLOW_LOGON_SCREEN_PASSWORD,
        OPTION_ONE_WAY_FILE_TRANSFER,
  • Loading branch information
rustdesk committed Sep 18, 2024
1 parent 49ce4ed commit cc28827
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 23 deletions.
8 changes: 8 additions & 0 deletions libs/hbb_common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,10 @@ pub mod keys {
pub const OPTION_HIDE_HELP_CARDS: &str = "hide-help-cards";
pub const OPTION_DEFAULT_CONNECT_PASSWORD: &str = "default-connect-password";
pub const OPTION_HIDE_TRAY: &str = "hide-tray";
pub const OPTION_ONE_WAY_CLIPBOARD_REDIRECTION: &str = "one-way-clipboard-redirection";
pub const OPTION_ENABLE_CLIPBOARD_INIT_SYNC: &str = "enable-clipboard-init-sync";
pub const OPTION_ALLOW_LOGON_SCREEN_PASSWORD: &str = "allow-logon-screen-password";
pub const OPTION_ONE_WAY_FILE_TRANSFER: &str = "one-way-file-transfer";

// flutter local options
pub const OPTION_FLUTTER_REMOTE_MENUBAR_STATE: &str = "remoteMenubarState";
Expand Down Expand Up @@ -2362,6 +2366,10 @@ pub mod keys {
OPTION_HIDE_HELP_CARDS,
OPTION_DEFAULT_CONNECT_PASSWORD,
OPTION_HIDE_TRAY,
OPTION_ONE_WAY_CLIPBOARD_REDIRECTION,
OPTION_ENABLE_CLIPBOARD_INIT_SYNC,
OPTION_ALLOW_LOGON_SCREEN_PASSWORD,
OPTION_ONE_WAY_FILE_TRANSFER,
];
}

Expand Down
6 changes: 6 additions & 0 deletions libs/hbb_common/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ where
libc::signal(libc::SIGSEGV, breakdown_signal_handler as _);
}
}

#[cfg(any(target_os = "android", target_os = "ios"))]
#[inline]
fn is_prelogin() -> bool {
false
}
23 changes: 14 additions & 9 deletions src/client/io_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crossbeam_queue::ArrayQueue;
use hbb_common::tokio::sync::mpsc::error::TryRecvError;
use hbb_common::{
allow_err,
config::{PeerConfig, TransferSerde},
config::{self, PeerConfig, TransferSerde},
fs::{
self, can_enable_overwrite_detection, get_job, get_string, new_send_confirm,
DigestCheckResult, RemoveJobMeta,
Expand Down Expand Up @@ -1201,13 +1201,18 @@ impl<T: InvokeUiSession> Remote<T> {
&peer_platform,
crate::clipboard::ClipboardSide::Client,
) {
let sender = self.sender.clone();
let permission_config = self.handler.get_permission_config();
tokio::spawn(async move {
if permission_config.is_text_clipboard_required() {
sender.send(Data::Message(msg_out)).ok();
}
});
if crate::get_builtin_option(
config::keys::OPTION_ENABLE_CLIPBOARD_INIT_SYNC,
) != "N"
{
let sender = self.sender.clone();
let permission_config = self.handler.get_permission_config();
tokio::spawn(async move {
if permission_config.is_text_clipboard_required() {
sender.send(Data::Message(msg_out)).ok();
}
});
}
}

// on connection established client
Expand Down Expand Up @@ -1618,7 +1623,7 @@ impl<T: InvokeUiSession> Remote<T> {
},
Some(message::Union::MessageBox(msgbox)) => {
let mut link = msgbox.link;
if let Some(v) = hbb_common::config::HELPER_URL.get(&link as &str) {
if let Some(v) = config::HELPER_URL.get(&link as &str) {
link = v.to_string();
} else {
log::warn!("Message box ignore link {} for security", &link);
Expand Down
10 changes: 10 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,3 +1650,13 @@ mod tests {
);
}
}

#[inline]
pub fn get_builtin_option(key: &str) -> String {
config::BUILTIN_SETTINGS
.read()
.unwrap()
.get(key)
.cloned()
.unwrap_or_default()
}
37 changes: 30 additions & 7 deletions src/server/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use hbb_common::platform::linux::run_cmds;
#[cfg(target_os = "android")]
use hbb_common::protobuf::EnumOrUnknown;
use hbb_common::{
config::{self, Config, TrustedDevice},
config::{self, keys, Config, TrustedDevice},
fs::{self, can_enable_overwrite_detection},
futures::{SinkExt, StreamExt},
get_time, get_version_number,
Expand Down Expand Up @@ -335,7 +335,7 @@ impl Connection {
clipboard: Connection::permission("enable-clipboard"),
audio: Connection::permission("enable-audio"),
// to-do: make sure is the option correct here
file: Connection::permission(config::keys::OPTION_ENABLE_FILE_TRANSFER),
file: Connection::permission(keys::OPTION_ENABLE_FILE_TRANSFER),
restart: Connection::permission("enable-remote-restart"),
recording: Connection::permission("enable-record-session"),
block_input: Connection::permission("enable-block-input"),
Expand Down Expand Up @@ -1359,7 +1359,10 @@ impl Connection {
if !self.follow_remote_window {
noperms.push(NAME_WINDOW_FOCUS);
}
if !self.clipboard_enabled() || !self.peer_keyboard_enabled() {
if !self.clipboard_enabled()
|| !self.peer_keyboard_enabled()
|| crate::get_builtin_option(keys::OPTION_ONE_WAY_CLIPBOARD_REDIRECTION) == "Y"
{
noperms.push(super::clipboard_service::NAME);
}
if !self.audio_enabled() {
Expand Down Expand Up @@ -1621,8 +1624,8 @@ impl Connection {
#[inline]
fn enable_trusted_devices() -> bool {
config::option2bool(
config::keys::OPTION_ENABLE_TRUSTED_DEVICES,
&Config::get_option(config::keys::OPTION_ENABLE_TRUSTED_DEVICES),
keys::OPTION_ENABLE_TRUSTED_DEVICES,
&Config::get_option(keys::OPTION_ENABLE_TRUSTED_DEVICES),
)
}

Expand Down Expand Up @@ -1689,7 +1692,7 @@ impl Connection {
}
match lr.union {
Some(login_request::Union::FileTransfer(ft)) => {
if !Connection::permission(config::keys::OPTION_ENABLE_FILE_TRANSFER) {
if !Connection::permission(keys::OPTION_ENABLE_FILE_TRANSFER) {
self.send_login_error("No permission of file transfer")
.await;
sleep(1.).await;
Expand Down Expand Up @@ -1762,7 +1765,9 @@ impl Connection {
self.send_login_error(crate::client::LOGIN_MSG_OFFLINE)
.await;
return false;
} else if password::approve_mode() == ApproveMode::Click
} else if (password::approve_mode() == ApproveMode::Click
&& !(crate::platform::is_prelogin()
&& crate::get_builtin_option(keys::OPTION_ALLOW_LOGON_SCREEN_PASSWORD) == "Y"))
|| password::approve_mode() == ApproveMode::Both && !password::has_valid_password()
{
self.try_start_cm(lr.my_id, lr.my_name, false);
Expand Down Expand Up @@ -2133,6 +2138,24 @@ impl Connection {
}
return true;
}
if crate::get_builtin_option(keys::OPTION_ONE_WAY_FILE_TRANSFER) == "Y" {
match fa.union {
Some(file_action::Union::Send(_))
| Some(file_action::Union::RemoveFile(_))
| Some(file_action::Union::Rename(_))
| Some(file_action::Union::Create(_))
| Some(file_action::Union::RemoveDir(_)) => {
self.send(fs::new_error(
0,
"One-way file transfer is enabled on controlled side",
0,
))
.await;
return true;
}
_ => {}
}
}
match fa.union {
Some(file_action::Union::ReadDir(rd)) => {
self.read_dir(&rd.path, rd.include_hidden);
Expand Down
2 changes: 1 addition & 1 deletion src/ui_cm_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
log::debug!(
"Process clipboard message from clip, stop: {}, is_stopping_allowed: {}, is_clipboard_enabled: {}, file_transfer_enabled: {}, file_transfer_enabled_peer: {}",
stop, is_stopping_allowed, is_clipboard_enabled, file_transfer_enabled, file_transfer_enabled_peer);
if stop {
if stop || crate::get_builtin_option(OPTION_ONE_WAY_FILE_TRANSFER) == "Y"{
ContextSend::set_is_stopped();
} else {
allow_err!(self.tx.send(Data::ClipboardFile(_clip)));
Expand Down
7 changes: 1 addition & 6 deletions src/ui_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,7 @@ pub fn get_hard_option(key: String) -> String {

#[inline]
pub fn get_builtin_option(key: &str) -> String {
config::BUILTIN_SETTINGS
.read()
.unwrap()
.get(key)
.cloned()
.unwrap_or_default()
crate::get_builtin_option(key)
}

#[inline]
Expand Down

0 comments on commit cc28827

Please sign in to comment.