Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
fe6ecfb
`IRP_MJ_CREATE` (#12665)
Jun 17, 2022
f40ccb0
`IRP_MJ_QUERY_INFORMATION` (#12717)
Jun 17, 2022
5900b7a
`IRP_MJ_CLOSE` (#12729)
Jun 17, 2022
cc6ab25
Refactor rdpdr client (#12750)
Jun 25, 2022
6a4ec1a
Adding logic for `FILE_SUPERSEDE` (#12829)
Jun 28, 2022
a8bac08
Improve `process_irp_create` (#12830)
Jun 28, 2022
6d9bb30
adds return statements that got lost in a merge
Jun 28, 2022
1ad2f69
`IRP_MJ_DIRECTORY_CONTROL` (#12870)
Jun 28, 2022
6b18b76
`FileFullDirectoryInformation` (#12908)
Jun 28, 2022
44ecdf5
Improve `ClientDriveQueryDirectoryResponse.encode()` (#12912)
Jun 29, 2022
6478e5f
`IRP_MJ_QUERY_VOLUME_INFORMATION` (#13071)
Jun 29, 2022
c2d50c9
Fix Shared Directory Request handling when feature is disabled (#13439)
Jun 29, 2022
69e05f1
IRP_MJ_READ, IRP_MJ_WRITE, and IRP_MJ_SET_INFORMATION (#13995)
May 18, 2022
2cd91e5
Adds constants for sizing calculations (#14051)
Jul 6, 2022
2741306
Merge branch 'master' into windows-desktop-directory-sharing
Jul 7, 2022
8454070
changes Id to ID
Jul 7, 2022
cda999f
fixes debug logging to be consistent with other logging
Jul 8, 2022
615f0d6
Adds UnixPath and WindowsPath to distinguish between path types
Jul 8, 2022
af886a9
`IRP_MJ_CREATE` (#12665)
Jun 17, 2022
cef7d8e
`IRP_MJ_QUERY_INFORMATION` (#12717)
Jun 17, 2022
2732c2c
`IRP_MJ_CLOSE` (#12729)
Jun 17, 2022
e38a14a
Refactor rdpdr client (#12750)
Jun 25, 2022
17ba911
Adding logic for `FILE_SUPERSEDE` (#12829)
Jun 28, 2022
60e5c5c
Improve `process_irp_create` (#12830)
Jun 28, 2022
b598b8e
adds return statements that got lost in a merge
Jun 28, 2022
c09ecb5
`IRP_MJ_DIRECTORY_CONTROL` (#12870)
Jun 28, 2022
c717131
`FileFullDirectoryInformation` (#12908)
Jun 28, 2022
4b74c82
Improve `ClientDriveQueryDirectoryResponse.encode()` (#12912)
Jun 29, 2022
99275d3
`IRP_MJ_QUERY_VOLUME_INFORMATION` (#13071)
Jun 29, 2022
6253cc7
Fix Shared Directory Request handling when feature is disabled (#13439)
Jun 29, 2022
0b772f9
IRP_MJ_READ, IRP_MJ_WRITE, and IRP_MJ_SET_INFORMATION (#13995)
May 18, 2022
9b060d0
Adds constants for sizing calculations (#14051)
Jul 6, 2022
be4bde0
changes Id to ID
Jul 7, 2022
335ae78
Updates SharedDirectoryReadResponse.Encode to avoid writing variable …
Jul 8, 2022
c16724b
Merge branch 'windows-desktop-directory-sharing' into isaiah/clean-pa…
Jul 14, 2022
3add207
Merge branch 'master' into windows-desktop-directory-sharing
Jul 21, 2022
5c67a42
deletes lib/srv/desktop/rdp/rdpclient/librdprs.h (as is the case on m…
Jul 21, 2022
f9af357
removing unused context and comment
Jul 19, 2022
36a5f9d
updates rdp-rs to latest
Jul 25, 2022
2552526
removes note-to-self TODO
Jul 26, 2022
be42a9d
removes unnecessary clones and revises comment
Jul 26, 2022
082398c
removes apostrophe
Jul 26, 2022
773cedd
removes all possible #[allow(dead_code)]
Jul 26, 2022
2e41c37
removes many uneeded else statements
Jul 26, 2022
d75e15a
Merge branch 'master' into windows-desktop-directory-sharing
Jul 26, 2022
474a3f6
Merge branch 'master' into windows-desktop-directory-sharing
Jul 26, 2022
bfdc8aa
adds documentation
Jul 26, 2022
f3aad5e
Merge branch 'master' into windows-desktop-directory-sharing
Jul 27, 2022
57e5b4c
Merge branch 'windows-desktop-directory-sharing' into isaiah/clean-pa…
Jul 27, 2022
38a5a40
switches 'impl From<WindowsPath> for UnixPath' to 'impl From<&Windows…
Aug 3, 2022
23cf137
swaps out new in favor of a From implementation for UnixPath and Wind…
Aug 3, 2022
22a2540
as_cstring becomes to_cstring
Aug 3, 2022
a2ee438
Merge branch 'master' into isaiah/clean-path-strings
Aug 6, 2022
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
2 changes: 1 addition & 1 deletion lib/srv/desktop/rdp/rdpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type Client struct {
}

// New creates and connects a new Client based on cfg.
func New(ctx context.Context, cfg Config) (*Client, error) {
func New(cfg Config) (*Client, error) {
if err := cfg.checkAndSetDefaults(); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/desktop/rdp/rdpclient/client_nop.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Client struct {
}

// New creates and connects a new Client based on opts.
func New(ctx context.Context, cfg Config) (*Client, error) {
func New(cfg Config) (*Client, error) {
return &Client{}, errors.New("the real rdpclient.Client implementation was not included in this build")
}

Expand Down
51 changes: 26 additions & 25 deletions lib/srv/desktop/rdp/rdpclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ use rdp::core::tpkt;
use rdp::core::x224;
use rdp::model::error::{Error as RdpError, RdpError as RdpProtocolError, RdpErrorKind, RdpResult};
use rdp::model::link::{Link, Stream};
use rdpdr::path::UnixPath;
use rdpdr::ServerCreateDriveRequest;
use std::convert::TryFrom;
use std::ffi::{CStr, CString};
use std::ffi::CStr;
use std::io::Error as IoError;
use std::io::ErrorKind;
use std::io::{Cursor, Read, Write};
Expand Down Expand Up @@ -306,7 +307,7 @@ fn connect_rdp_inner(
let tdp_sd_info_request = Box::new(move |req: SharedDirectoryInfoRequest| -> RdpResult<()> {
debug!("sending TDP SharedDirectoryInfoRequest: {:?}", req);
// Create C compatible string from req.path
match CString::new(req.path.clone()) {
match req.path.to_cstring() {
Ok(c_string) => {
unsafe {
let err = tdp_sd_info_request(
Expand All @@ -328,7 +329,7 @@ fn connect_rdp_inner(
Err(_) => {
// TODO(isaiah): change TryError to TeleportError for a generic error caused by Teleport specific code.
return Err(RdpError::TryError(format!(
"path contained characters that couldn't be converted to a C string: {}",
"path contained characters that couldn't be converted to a C string: {:?}",
req.path
)));
}
Expand All @@ -339,7 +340,7 @@ fn connect_rdp_inner(
Box::new(move |req: SharedDirectoryCreateRequest| -> RdpResult<()> {
debug!("sending TDP SharedDirectoryCreateRequest: {:?}", req);
// Create C compatible string from req.path
match CString::new(req.path.clone()) {
match req.path.to_cstring() {
Ok(c_string) => {
unsafe {
let err = tdp_sd_create_request(
Expand All @@ -362,7 +363,7 @@ fn connect_rdp_inner(
Err(_) => {
// TODO(isaiah): change TryError to TeleportError for a generic error caused by Teleport specific code.
return Err(RdpError::TryError(format!(
"path contained characters that couldn't be converted to a C string: {}",
"path contained characters that couldn't be converted to a C string: {:?}",
req.path
)));
}
Expand All @@ -373,7 +374,7 @@ fn connect_rdp_inner(
Box::new(move |req: SharedDirectoryDeleteRequest| -> RdpResult<()> {
debug!("sending TDP SharedDirectoryDeleteRequest: {:?}", req);
// Create C compatible string from req.path
match CString::new(req.path.clone()) {
match req.path.to_cstring() {
Ok(c_string) => {
unsafe {
let err = tdp_sd_delete_request(
Expand All @@ -395,7 +396,7 @@ fn connect_rdp_inner(
Err(_) => {
// TODO(isaiah): change TryError to TeleportError for a generic error caused by Teleport specific code.
return Err(RdpError::TryError(format!(
"path contained characters that couldn't be converted to a C string: {}",
"path contained characters that couldn't be converted to a C string: {:?}",
req.path
)));
}
Expand All @@ -405,7 +406,7 @@ fn connect_rdp_inner(
let tdp_sd_list_request = Box::new(move |req: SharedDirectoryListRequest| -> RdpResult<()> {
debug!("sending TDP SharedDirectoryListRequest: {:?}", req);
// Create C compatible string from req.path
match CString::new(req.path.clone()) {
match req.path.to_cstring() {
Ok(c_string) => {
unsafe {
let err = tdp_sd_list_request(
Expand All @@ -427,16 +428,16 @@ fn connect_rdp_inner(
Err(_) => {
// TODO(isaiah): change TryError to TeleportError for a generic error caused by Teleport specific code.
return Err(RdpError::TryError(format!(
"path contained characters that couldn't be converted to a C string: {}",
"path contained characters that couldn't be converted to a C string: {:?}",
req.path
)));
}
}
});

let tdp_sd_read_request = Box::new(move |req: SharedDirectoryReadRequest| -> RdpResult<()> {
debug!("sending: {:?}", req);
match CString::new(req.path.clone()) {
debug!("sending TDP SharedDirectoryReadRequest: {:?}", req);
match req.path.to_cstring() {
Ok(c_string) => {
unsafe {
let err = tdp_sd_read_request(
Expand All @@ -445,7 +446,7 @@ fn connect_rdp_inner(
completion_id: req.completion_id,
directory_id: req.directory_id,
path: c_string.as_ptr(),
path_length: req.path.len() as u32,
path_length: req.path.len(),
offset: req.offset,
length: req.length,
},
Expand All @@ -461,16 +462,16 @@ fn connect_rdp_inner(
}
Err(_) => {
return Err(RdpError::TryError(format!(
"path contained characters that couldn't be converted to a C string: {}",
"path contained characters that couldn't be converted to a C string: {:?}",
req.path
)));
}
}
});

let tdp_sd_write_request = Box::new(move |req: SharedDirectoryWriteRequest| -> RdpResult<()> {
debug!("sending: {:?}", req);
match CString::new(req.path.clone()) {
debug!("sending TDP SharedDirectoryWriteRequest: {:?}", req);
match req.path.to_cstring() {
Ok(c_string) => {
unsafe {
let err = tdp_sd_write_request(
Expand All @@ -480,7 +481,7 @@ fn connect_rdp_inner(
directory_id: req.directory_id,
offset: req.offset,
path: c_string.as_ptr(),
path_length: req.path.len() as u32,
path_length: req.path.len(),
write_data_length: req.write_data.len() as u32,
write_data: req.write_data.as_ptr() as *mut u8,
},
Expand All @@ -496,7 +497,7 @@ fn connect_rdp_inner(
}
Err(_) => {
return Err(RdpError::TryError(format!(
"path contained characters that couldn't be converted to a C string: {}",
"path contained characters that couldn't be converted to a C string: {:?}",
req.path
)));
}
Expand Down Expand Up @@ -1365,7 +1366,7 @@ pub type CGOSharedDirectoryAcknowledge = SharedDirectoryAcknowledge;
pub struct SharedDirectoryInfoRequest {
completion_id: u32,
directory_id: u32,
path: String,
path: UnixPath,
}

#[repr(C)]
Expand All @@ -1380,7 +1381,7 @@ impl From<ServerCreateDriveRequest> for SharedDirectoryInfoRequest {
SharedDirectoryInfoRequest {
completion_id: req.device_io_request.completion_id,
directory_id: req.device_io_request.device_id,
path: req.path,
path: UnixPath::from(&req.path),
}
}
}
Expand Down Expand Up @@ -1423,12 +1424,12 @@ pub struct FileSystemObject {
last_modified: u64,
size: u64,
file_type: FileType,
path: String,
path: UnixPath,
}

impl FileSystemObject {
fn name(&self) -> RdpResult<String> {
if let Some(name) = self.path.split('/').last() {
if let Some(name) = self.path.last() {
Ok(name.to_string())
} else {
Err(try_error(&format!(
Expand Down Expand Up @@ -1460,7 +1461,7 @@ impl From<CGOFileSystemObject> for FileSystemObject {
last_modified: cgo_fso.last_modified,
size: cgo_fso.size,
file_type: cgo_fso.file_type,
path: from_go_string(cgo_fso.path),
path: UnixPath::from(from_go_string(cgo_fso.path)),
}
}
}
Expand Down Expand Up @@ -1493,7 +1494,7 @@ pub struct SharedDirectoryWriteRequest {
completion_id: u32,
directory_id: u32,
offset: u64,
path: String,
path: UnixPath,
write_data: Vec<u8>,
}

Expand All @@ -1515,7 +1516,7 @@ pub struct CGOSharedDirectoryWriteRequest {
pub struct SharedDirectoryReadRequest {
completion_id: u32,
directory_id: u32,
path: String,
path: UnixPath,
offset: u64,
length: u32,
}
Expand Down Expand Up @@ -1580,7 +1581,7 @@ pub struct SharedDirectoryCreateRequest {
completion_id: u32,
directory_id: u32,
file_type: FileType,
path: String,
path: UnixPath,
}

#[repr(C)]
Expand Down
34 changes: 19 additions & 15 deletions lib/srv/desktop/rdp/rdpclient/src/rdpdr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

mod consts;
mod flags;
pub(crate) mod path;
mod scard;

use self::path::{UnixPath, WindowsPath};
use crate::errors::{
invalid_data_error, not_implemented_error, rejected_by_server_error, try_error, NTSTATUS_OK,
SPECIAL_NO_RESPONSE,
Expand Down Expand Up @@ -462,7 +464,7 @@ impl Client {
let file_id = cli.generate_file_id();
cli.file_cache.insert(
file_id,
FileCacheObject::new(rdp_req.path.clone(), res.fso),
FileCacheObject::new(UnixPath::from(&rdp_req.path), res.fso),
);
return cli.prep_device_create_response(
&rdp_req,
Expand Down Expand Up @@ -495,7 +497,7 @@ impl Client {
let file_id = cli.generate_file_id();
cli.file_cache.insert(
file_id,
FileCacheObject::new(rdp_req.path.clone(), res.fso),
FileCacheObject::new(UnixPath::from(&rdp_req.path), res.fso),
);
return cli.prep_device_create_response(
&rdp_req,
Expand Down Expand Up @@ -1144,7 +1146,7 @@ impl Client {
completion_id: rdp_req.device_io_request.completion_id,
directory_id: rdp_req.device_io_request.device_id,
file_type,
path: rdp_req.path.clone(),
path: UnixPath::from(&rdp_req.path),
};
(self.tdp_sd_create_request)(tdp_req)?;

Expand All @@ -1163,8 +1165,10 @@ impl Client {
}

let file_id = cli.generate_file_id();
cli.file_cache
.insert(file_id, FileCacheObject::new(rdp_req.path.clone(), fso));
cli.file_cache.insert(
file_id,
FileCacheObject::new(UnixPath::from(&rdp_req.path), fso),
);
cli.prep_device_create_response(&rdp_req, NTSTATUS::STATUS_SUCCESS, file_id)
},
),
Expand All @@ -1183,7 +1187,7 @@ impl Client {
let tdp_req = SharedDirectoryDeleteRequest {
completion_id: rdp_req.device_io_request.completion_id,
directory_id: rdp_req.device_io_request.device_id,
path: rdp_req.path.clone(),
path: UnixPath::from(&rdp_req.path),
};
(self.tdp_sd_delete_request)(tdp_req)?;
self.pending_sd_delete_resp_handlers.insert(
Expand Down Expand Up @@ -1369,7 +1373,7 @@ impl Client {
/// | -------- | ------------- | ---------------------------------------------------------|
#[derive(Debug)]
struct FileCacheObject {
path: String,
path: UnixPath,
delete_pending: bool,
/// The FileSystemObject pertaining to the file or directory at path.
fso: FileSystemObject,
Expand All @@ -1385,7 +1389,7 @@ struct FileCacheObject {
}

impl FileCacheObject {
fn new(path: String, fso: FileSystemObject) -> Self {
fn new(path: UnixPath, fso: FileSystemObject) -> Self {
Self {
path,
delete_pending: false,
Expand Down Expand Up @@ -1427,7 +1431,7 @@ impl Iterator for FileCacheObject {
last_modified: self.fso.last_modified,
size: self.fso.size,
file_type: self.fso.file_type,
path: ".".to_string(),
path: UnixPath::from(".".to_string()),
})
} else if !self.dotdot_sent {
// On the second call to next, return the ".." directory
Expand All @@ -1436,7 +1440,7 @@ impl Iterator for FileCacheObject {
last_modified: self.fso.last_modified,
size: 0,
file_type: FileType::Directory,
path: "..".to_string(),
path: UnixPath::from("..".to_string()),
})
} else {
// "." and ".." have been sent, now start iterating through
Expand Down Expand Up @@ -2089,7 +2093,7 @@ pub struct DeviceCreateRequest {
create_disposition: flags::CreateDisposition,
create_options: flags::CreateOptions,
path_length: u32,
pub path: String,
pub path: WindowsPath,
}

impl DeviceCreateRequest {
Expand All @@ -2114,7 +2118,7 @@ impl DeviceCreateRequest {
// for a u32 will never panic on the machines that run teleport.
let mut path = vec![0u8; path_length.try_into().unwrap()];
payload.read_exact(&mut path)?;
let path = util::from_unicode(path)?;
let path = WindowsPath::from(util::from_unicode(path)?);

Ok(Self {
device_io_request,
Expand Down Expand Up @@ -3451,7 +3455,7 @@ struct ServerDriveQueryDirectoryRequest {
/// A variable-length array of Unicode characters (we will store this as a regular rust String) that specifies the directory
/// on which this operation will be performed. The Path field MUST be null-terminated. If the value of the InitialQuery field
/// is zero, then the contents of the Path field MUST be ignored, irrespective of the value specified in the PathLength field.
path: String,
path: WindowsPath,
}

impl ServerDriveQueryDirectoryRequest {
Expand All @@ -3478,7 +3482,7 @@ impl ServerDriveQueryDirectoryRequest {

let initial_query = payload.read_u8()?;
let mut path_length: u32 = 0;
let mut path = String::from("");
let mut path = WindowsPath::from("".to_string());
let mut padding: [u8; 23] = [0; 23];
if initial_query != 0 {
path_length = payload.read_u32::<LittleEndian>()?;
Expand All @@ -3489,7 +3493,7 @@ impl ServerDriveQueryDirectoryRequest {
// TODO(isaiah): make a from_unicode_exact
let mut path_as_vec = vec![0u8; path_length.try_into().unwrap()];
payload.read_exact(&mut path_as_vec)?;
path = util::from_unicode(path_as_vec)?;
path = WindowsPath::from(util::from_unicode(path_as_vec)?);
}

Ok(Self {
Expand Down
Loading