From 6445ee03b86e7a01101edf966d67e715563e971c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 3 Dec 2024 16:01:55 +0400 Subject: [PATCH] rdp: add .ListenAddress property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- qemu-rdp/src/args.rs | 2 +- qemu-rdp/src/server/mod.rs | 67 +++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/qemu-rdp/src/args.rs b/qemu-rdp/src/args.rs index c4892a4..f056ddd 100644 --- a/qemu-rdp/src/args.rs +++ b/qemu-rdp/src/args.rs @@ -30,7 +30,7 @@ pub enum Commands { pub struct ServerArgs { /// IP address #[clap(short, long, default_value = "0.0.0.0:3389")] - pub bind_addr: std::net::SocketAddr, + pub bind_address: std::net::SocketAddr, /// Path to tls certificate #[clap(short, long, value_parser)] diff --git a/qemu-rdp/src/server/mod.rs b/qemu-rdp/src/server/mod.rs index fef3fce..d39a798 100644 --- a/qemu-rdp/src/server/mod.rs +++ b/qemu-rdp/src/server/mod.rs @@ -1,22 +1,19 @@ +use anyhow::{bail, Error}; +use enumflags2::BitFlags; +use ironrdp::server::{Credentials, ServerEvent, TlsIdentityCtx}; +use std::path::PathBuf; +use tokio::sync::{mpsc::UnboundedSender, oneshot}; +use tracing::{debug, error}; + +use ironrdp::server::RdpServer; +use qemu_display::{zbus, Display}; + mod clipboard; mod display; mod input; mod sound; -use std::path::PathBuf; - -use anyhow::{bail, Error}; -use enumflags2::BitFlags; -use ironrdp::server::{Credentials, ServerEvent, TlsIdentityCtx}; - -use qemu_display::{zbus, Display}; -use tokio::sync::mpsc::UnboundedSender; -use tracing::debug; - -use ironrdp::server::RdpServer; - use crate::args::ServerArgs; - use clipboard::ClipboardHandler; use display::DisplayHandler; use input::InputHandler; @@ -71,7 +68,7 @@ impl Server { let tls = TlsIdentityCtx::init_from_paths(&cert, &key)?; let mut server = RdpServer::builder() - .with_addr(self.args.bind_addr) + .with_addr(self.args.bind_address) .with_hybrid(tls.make_acceptor()?, tls.pub_key) .with_input_handler(handler) .with_display_handler(display) @@ -94,7 +91,7 @@ impl Server { let ev = server.event_sender().clone(); self.dbus .object_server() - .at("/org/qemu_display/rdp", DBusCtrl { ev }) + .at("/org/qemu_rdp", DBusCtrl { ev }) .await?; self.dbus .request_name_with_flags("org.QemuDisplay", BitFlags::EMPTY) @@ -108,19 +105,35 @@ impl Server { } } -#[zbus::interface(name = "org.QemuDisplay.RDP")] +#[zbus::interface(name = "org.QemuRDP")] impl DBusCtrl { async fn set_credentials(&self, username: &str, password: &str, domain: &str) { - self.ev - .send(ServerEvent::SetCredentials(Credentials { - username: username.into(), - password: password.into(), - domain: if domain.is_empty() { - None - } else { - Some(domain.into()) - }, - })) - .unwrap(); + if let Err(error) = self.ev.send(ServerEvent::SetCredentials(Credentials { + username: username.into(), + password: password.into(), + domain: if domain.is_empty() { + None + } else { + Some(domain.into()) + }, + })) { + error!(?error, "Failed to send SetCredentials") + } + } + + #[zbus(property)] + async fn listen_address(&self) -> zbus::fdo::Result { + let (tx, rx) = oneshot::channel(); + if let Err(error) = self.ev.send(ServerEvent::GetLocalAddr(tx)) { + error!(?error, "Failed to send GetLocalAddr") + } + if let Some(addr) = rx + .await + .map_err(|e| zbus::fdo::Error::Failed(e.to_string()))? + { + Ok(addr.to_string()) + } else { + Err(zbus::fdo::Error::Failed("Not yet available".into())) + } } }