Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/srv/desktop/rdp/rdpclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ pub enum TdpErrCode {

/// SharedDirectoryWriteRequest is sent by the TDP server to the client
/// to write to a file.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct SharedDirectoryWriteRequest {
completion_id: u32,
directory_id: u32,
Expand All @@ -1575,6 +1575,18 @@ pub struct SharedDirectoryWriteRequest {
write_data: Vec<u8>,
}

impl std::fmt::Debug for SharedDirectoryWriteRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SharedDirectoryWriteRequest")
.field("completion_id", &self.completion_id)
.field("directory_id", &self.directory_id)
.field("offset", &self.offset)
.field("path", &self.path)
.field("write_data", &util::vec_u8_debug(&self.write_data))
.finish()
}
}

#[derive(Debug)]
#[repr(C)]
pub struct CGOSharedDirectoryWriteRequest {
Expand Down Expand Up @@ -1610,14 +1622,23 @@ pub struct CGOSharedDirectoryReadRequest {

/// SharedDirectoryReadResponse is sent by the TDP client to the server
/// with the data as requested by a SharedDirectoryReadRequest.
#[derive(Debug)]
#[repr(C)]
pub struct SharedDirectoryReadResponse {
pub completion_id: u32,
pub err_code: TdpErrCode,
pub read_data: Vec<u8>,
}

impl std::fmt::Debug for SharedDirectoryReadResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SharedDirectoryReadResponse")
.field("completion_id", &self.completion_id)
.field("err_code", &self.err_code)
.field("read_data", &util::vec_u8_debug(&self.read_data))
.finish()
}
}

impl From<CGOSharedDirectoryReadResponse> for SharedDirectoryReadResponse {
fn from(cgo_response: CGOSharedDirectoryReadResponse) -> SharedDirectoryReadResponse {
unsafe {
Expand Down
24 changes: 22 additions & 2 deletions lib/srv/desktop/rdp/rdpclient/src/rdpdr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3407,7 +3407,6 @@ impl DeviceReadRequest {

/// 2.2.1.5.3 Device Read Response (DR_READ_RSP)
/// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpefs/d35d3f91-fc5b-492b-80be-47f483ad1dc9
#[derive(Debug)]
struct DeviceReadResponse {
/// The CompletionId field of this header MUST match a Device I/O Request (section 2.2.1.4) message that had the MajorFunction field set to IRP_MJ_READ.
device_io_reply: DeviceIoResponse,
Expand All @@ -3417,6 +3416,16 @@ struct DeviceReadResponse {
read_data: Vec<u8>,
}

impl std::fmt::Debug for DeviceReadResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DeviceReadResponse")
.field("device_io_reply", &self.device_io_reply)
.field("length", &self.length)
.field("read_data", &util::vec_u8_debug(&self.read_data))
.finish()
}
}

impl DeviceReadResponse {
fn new(
device_read_request: &DeviceReadRequest,
Expand Down Expand Up @@ -3446,7 +3455,7 @@ impl DeviceReadResponse {

/// 2.2.1.4.4 Device Write Request (DR_WRITE_REQ)
/// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpefs/2e25f0aa-a4ce-4ff3-ad62-ab6098280a3a
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct DeviceWriteRequest {
/// The MajorFunction field in this header MUST be set to IRP_MJ_WRITE.
pub device_io_request: DeviceIoRequest,
Expand All @@ -3458,6 +3467,17 @@ pub struct DeviceWriteRequest {
pub write_data: Vec<u8>,
}

impl std::fmt::Debug for DeviceWriteRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DeviceWriteRequest")
.field("device_io_request", &self.device_io_request)
.field("length", &self.length)
.field("offset", &self.offset)
.field("write_data", &util::vec_u8_debug(&self.write_data))
.finish()
}
}

impl DeviceWriteRequest {
fn decode(device_io_request: DeviceIoRequest, payload: &mut Payload) -> RdpResult<Self> {
let length = payload.read_u32::<LittleEndian>()?;
Expand Down
4 changes: 4 additions & 0 deletions lib/srv/desktop/rdp/rdpclient/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub fn unicode_size(s: &str, with_null_term: bool) -> u32 {
u32::try_from(to_unicode(s, with_null_term).len()).unwrap()
}

pub fn vec_u8_debug(v: &[u8]) -> String {
format!("&[u8] of length {}", v.len())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down