Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for SharedDirectoryCreateRequest and SharedDirectoryCreateResponse. #34011

Merged
merged 14 commits into from
Nov 14, 2023
Merged
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions lib/srv/desktop/rdp/rdpclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ x509-parser = "0.14"
sspi = { version = "0.10.1", features = ["network_client", "dns_resolver"] }
static_init = "1.0.3"

ironrdp-connector = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-tls = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-session = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-pdu = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-tokio = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-rdpsnd = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-rdpdr = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-svc = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-cliprdr = { git = "https://github.com/Devolutions/IronRDP", rev = "2075833ff2d02e6cea256e8a24e4e6e5e805ce88" }
ironrdp-connector = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-tls = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-session = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-pdu = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-tokio = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-rdpsnd = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-rdpdr = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-svc = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }
ironrdp-cliprdr = { git = "https://github.com/Devolutions/IronRDP", rev = "9859cb7518c5aa1635abe51fd74f97eb3eefad5d" }

# Uncomment the following lines to use local crates instead of the ones from github
# ironrdp-connector = { path = "/Users/ibeckermayer/Devolutions/IronRDP/crates/ironrdp-connector" }
Expand Down
95 changes: 74 additions & 21 deletions lib/srv/desktop/rdp/rdpclient/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@ use crate::cliprdr::{ClipboardFn, TeleportCliprdrBackend};
use crate::rdpdr::scard::SCARD_DEVICE_ID;
use crate::rdpdr::TeleportRdpdrBackend;

#[macro_use]
mod macros {
macro_rules! get_svc_processor {
($x224_processor:expr, $svc_processor:ty) => {
$x224_processor
.get_svc_processor::<$svc_processor>()
.ok_or(ClientError::InternalError)?
};
}

macro_rules! get_svc_processor_mut {
($x224_processor:expr, $svc_processor:ty) => {
$x224_processor
.get_svc_processor_mut::<$svc_processor>()
.ok_or(ClientError::InternalError)?
};
}

macro_rules! get_backend_mut {
($x224_processor:expr, $svc_processor:ty, $backend:ty) => {
get_svc_processor_mut!($x224_processor, $svc_processor)
.downcast_backend_mut::<$backend>()
.ok_or(ClientError::InternalError)?
};
}
}
ibeckermayer marked this conversation as resolved.
Show resolved Hide resolved

/// The RDP client on the Rust side of things. Each `Client`
/// corresponds with a Go `Client` specified by `cgo_handle`.
pub struct Client {
Expand Down Expand Up @@ -96,11 +123,11 @@ impl Client {

let mut rdpdr = Rdpdr::new(
Box::new(TeleportRdpdrBackend::new(
SCARD_DEVICE_ID,
client_handle.clone(),
params.cert_der,
params.key_der,
pin,
cgo_handle,
)),
"IronRDP".to_string(),
)
Expand Down Expand Up @@ -295,7 +322,6 @@ impl Client {
Client::write_raw_pdu(&mut write_stream, args).await?;
}
ClientFunction::WriteRdpdr(args) => {
debug!("sending: {:?}", args);
Client::write_rdpdr(&mut write_stream, x224_processor.clone(), args)
.await?;
}
Expand All @@ -307,6 +333,14 @@ impl Client {
)
.await?;
}
ClientFunction::HandleTdpSdInfoResponse(res) => {
Client::handle_tdp_sd_info_response(x224_processor.clone(), res)
.await?;
}
ClientFunction::HandleTdpSdCreateResponse(res) => {
Client::handle_tdp_sd_create_response(x224_processor.clone(), res)
.await?;
}
ClientFunction::WriteCliprdr(f) => {
Client::write_cliprdr(x224_processor.clone(), &mut write_stream, f)
.await?;
Expand Down Expand Up @@ -337,11 +371,7 @@ impl Client {
global::TOKIO_RT
.spawn_blocking(move || {
let mut x224_processor = Self::x224_lock(&x224_processor)?;
let cliprdr = x224_processor
.get_svc_processor_mut::<Cliprdr>()
.ok_or(ClientError::InternalError)?
.downcast_backend_mut::<TeleportCliprdrBackend>()
.ok_or(ClientError::InternalError)?;
let cliprdr = get_backend_mut!(x224_processor, Cliprdr, TeleportCliprdrBackend);
cliprdr.set_clipboard_data(data.clone());
Ok(())
})
Expand All @@ -366,9 +396,7 @@ impl Client {
let messages: ClientResult<CliprdrSvcMessages> = global::TOKIO_RT
.spawn_blocking(move || {
let mut x224_processor = Self::x224_lock(&processor)?;
let cliprdr = x224_processor
.get_svc_processor::<Cliprdr>()
.ok_or(ClientError::InternalError)?;
let cliprdr = get_svc_processor!(x224_processor, Cliprdr);
Ok(fun.call(cliprdr)?)
})
.await?;
Expand Down Expand Up @@ -455,6 +483,7 @@ impl Client {
x224_processor: Arc<Mutex<X224Processor>>,
pdu: RdpdrPdu,
) -> ClientResult<()> {
debug!("sending rdp: {:?}", pdu);
// Process the RDPDR PDU.
let encoded = Client::x224_process_svc_messages(
x224_processor,
Expand All @@ -472,7 +501,7 @@ impl Client {
x224_processor: Arc<Mutex<X224Processor>>,
sda: tdp::SharedDirectoryAnnounce,
) -> ClientResult<()> {
debug!("handling tdp sd announce: {:?}", sda);
debug!("received tdp: {:?}", sda);
let pdu = Self::add_drive(x224_processor.clone(), sda).await?;
Self::write_rdpdr(
write_stream,
Expand All @@ -483,27 +512,47 @@ impl Client {
Ok(())
}

async fn handle_tdp_sd_info_response(
x224_processor: Arc<Mutex<X224Processor>>,
res: tdp::SharedDirectoryInfoResponse,
) -> ClientResult<()> {
global::TOKIO_RT
.spawn_blocking(move || {
debug!("received tdp: {:?}", res);
let mut x224_processor = Self::x224_lock(&x224_processor)?;
let rdpdr = get_backend_mut!(x224_processor, Rdpdr, TeleportRdpdrBackend);
rdpdr.handle_tdp_sd_info_response(res)?;
Ok(())
})
.await?
}

async fn handle_tdp_sd_create_response(
x224_processor: Arc<Mutex<X224Processor>>,
res: tdp::SharedDirectoryCreateResponse,
) -> ClientResult<()> {
global::TOKIO_RT
.spawn_blocking(move || {
debug!("received tdp: {:?}", res);
let mut x224_processor = Self::x224_lock(&x224_processor)?;
let rdpdr = get_backend_mut!(x224_processor, Rdpdr, TeleportRdpdrBackend);
rdpdr.handle_tdp_sd_create_response(res)?;
Ok(())
})
.await?
}

async fn add_drive(
x224_processor: Arc<Mutex<X224Processor>>,
sda: tdp::SharedDirectoryAnnounce,
) -> ClientResult<ClientDeviceListAnnounce> {
global::TOKIO_RT
.spawn_blocking(move || {
let mut x224_processor = Self::x224_lock(&x224_processor)?;

let rdpdr = x224_processor
.get_svc_processor_mut::<Rdpdr>()
.ok_or(ClientError::InternalError)?;
// Add drive to rdpdr
let pdu = rdpdr.add_drive(sda.directory_id, sda.name);

let teleport_rdpdr_backend = rdpdr
.downcast_backend_mut::<TeleportRdpdrBackend>()
.ok_or(ClientError::InternalError)?;
// Add device_id to teleport rdpdr backend
teleport_rdpdr_backend.add_active_device_id(sda.directory_id);

// Return the ClientDeviceListAnnounce for sending to the server.
Ok(pdu)
})
.await?
Expand Down Expand Up @@ -573,6 +622,10 @@ pub enum ClientFunction {
WriteRdpdr(RdpdrPdu),
/// Corresponds to [`Client::handle_tdp_sd_announce`]
HandleTdpSdAnnounce(tdp::SharedDirectoryAnnounce),
/// Corresponds to [`Client::handle_tdp_sd_info_response`]
HandleTdpSdInfoResponse(tdp::SharedDirectoryInfoResponse),
/// Corresponds to [`Client::handle_tdp_sd_create_response`]
HandleTdpSdCreateResponse(tdp::SharedDirectoryCreateResponse),
/// Corresponds to [`Client::write_cliprdr`]
WriteCliprdr(Box<dyn ClipboardFn>),
/// Corresponds to [`Client::update_clipboard`]
Expand Down
13 changes: 7 additions & 6 deletions lib/srv/desktop/rdp/rdpclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use ironrdp_pdu::{other_err, PduError};
use ironrdp_session::image::DecodedImage;
use rdpdr::path::UnixPath;
use rdpdr::tdp::{
FileSystemObject, FileType, SharedDirectoryAcknowledge, SharedDirectoryDeleteResponse,
SharedDirectoryMoveResponse, SharedDirectoryWriteResponse, TdpErrCode,
FileSystemObject, FileType, SharedDirectoryAcknowledge, SharedDirectoryCreateResponse,
SharedDirectoryDeleteResponse, SharedDirectoryInfoResponse, SharedDirectoryMoveResponse,
SharedDirectoryWriteResponse, TdpErrCode,
};
use std::convert::TryFrom;
use std::ffi::CString;
Expand Down Expand Up @@ -191,8 +192,8 @@ pub unsafe extern "C" fn client_handle_tdp_sd_info_response(
cgo_handle: CgoHandle,
res: CGOSharedDirectoryInfoResponse,
) -> CGOErrCode {
warn!("unimplemented: client_handle_tdp_sd_info_response");
CGOErrCode::ErrCodeSuccess
let res = SharedDirectoryInfoResponse::from(res);
call_function_on_handle(cgo_handle, ClientFunction::HandleTdpSdInfoResponse(res))
}

/// client_handle_tdp_sd_create_response handles a TDP Shared Directory Create Response
Expand All @@ -207,8 +208,8 @@ pub unsafe extern "C" fn client_handle_tdp_sd_create_response(
cgo_handle: CgoHandle,
res: CGOSharedDirectoryCreateResponse,
) -> CGOErrCode {
warn!("unimplemented: client_handle_tdp_sd_create_response");
CGOErrCode::ErrCodeSuccess
let res = SharedDirectoryCreateResponse::from(res);
call_function_on_handle(cgo_handle, ClientFunction::HandleTdpSdCreateResponse(res))
}

/// client_handle_tdp_sd_delete_response handles a TDP Shared Directory Delete Response
Expand Down
Loading
Loading