Skip to content

Commit

Permalink
Restructure rdpdr.rs into a multi file module (#12530)
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Becker-Mayer authored May 9, 2022
1 parent dde7bb7 commit fd750dd
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 134 deletions.
24 changes: 24 additions & 0 deletions lib/srv/desktop/dir_sharing_disabled.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build !directory_sharing
// +build !directory_sharing

/*
Copyright 2022 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package desktop

func allowDirectorySharing() bool {
return false
}
24 changes: 24 additions & 0 deletions lib/srv/desktop/dir_sharing_enabled.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build directory_sharing
// +build directory_sharing

/*
Copyright 2022 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package desktop

func allowDirectorySharing() bool {
return true
}
1 change: 1 addition & 0 deletions lib/srv/desktop/rdp/rdpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (c *Client) connect(ctx context.Context) error {
C.uint16_t(c.clientWidth),
C.uint16_t(c.clientHeight),
C.bool(c.cfg.AllowClipboard),
C.bool(c.cfg.AllowDirectorySharing),
)
if res.err != C.ErrCodeSuccess {
return trace.ConnectionProblem(nil, "RDP connection failed")
Expand Down
4 changes: 4 additions & 0 deletions lib/srv/desktop/rdp/rdpclient/client_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type Config struct {
// clipboard sharing.
AllowClipboard bool

// AllowDirectorySharing indicates whether the RDP connection should enable
// directory sharing.
AllowDirectorySharing bool

// Log is the logger for status messages.
Log logrus.FieldLogger
}
Expand Down
15 changes: 14 additions & 1 deletion lib/srv/desktop/rdp/rdpclient/librdprs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

#define SPECIAL_NO_RESPONSE 4294967295

#define VERSION_MAJOR 1

#define VERSION_MINOR 12

#define SMARTCARD_CAPABILITY_VERSION_01 1

#define GENERAL_CAPABILITY_VERSION_01 1

#define GENERAL_CAPABILITY_VERSION_02 2

#define SCARD_DEVICE_ID 1

/**
* The default maximum chunk size for virtual channel data.
*
Expand Down Expand Up @@ -116,7 +128,8 @@ struct ClientOrError connect_rdp(uintptr_t go_ref,
uint8_t *key_der,
uint16_t screen_width,
uint16_t screen_height,
bool allow_clipboard);
bool allow_clipboard,
bool allow_directory_sharing);

/**
* `update_clipboard` is called from Go, and caches data that was copied
Expand Down
11 changes: 9 additions & 2 deletions lib/srv/desktop/rdp/rdpclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod cliprdr;
pub mod errors;
pub mod piv;
pub mod rdpdr;
pub mod scard;
pub mod util;
pub mod vchan;

Expand Down Expand Up @@ -130,6 +129,7 @@ pub unsafe extern "C" fn connect_rdp(
screen_width: u16,
screen_height: u16,
allow_clipboard: bool,
allow_directory_sharing: bool,
) -> ClientOrError {
// Convert from C to Rust types.
let addr = from_go_string(go_addr);
Expand All @@ -147,6 +147,7 @@ pub unsafe extern "C" fn connect_rdp(
screen_width,
screen_height,
allow_clipboard,
allow_directory_sharing,
},
)
.into()
Expand Down Expand Up @@ -180,6 +181,7 @@ struct ConnectParams {
screen_width: u16,
screen_height: u16,
allow_clipboard: bool,
allow_directory_sharing: bool,
}

fn connect_rdp_inner(
Expand Down Expand Up @@ -246,7 +248,12 @@ fn connect_rdp_inner(
"rdp-rs",
);
// Client for the "rdpdr" channel - smartcard emulation.
let rdpdr = rdpdr::Client::new(params.cert_der, params.key_der, pin);
let rdpdr = rdpdr::Client::new(
params.cert_der,
params.key_der,
pin,
params.allow_directory_sharing,
);

// Client for the "cliprdr" channel - clipboard sharing.
let cliprdr = if params.allow_clipboard {
Expand Down
96 changes: 96 additions & 0 deletions lib/srv/desktop/rdp/rdpclient/src/rdpdr/consts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2022 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub const CHANNEL_NAME: &str = "rdpdr";

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum Component {
RDPDR_CTYP_CORE = 0x4472,
RDPDR_CTYP_PRN = 0x5052,
}

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum PacketId {
PAKID_CORE_SERVER_ANNOUNCE = 0x496E,
PAKID_CORE_CLIENTID_CONFIRM = 0x4343,
PAKID_CORE_CLIENT_NAME = 0x434E,
PAKID_CORE_DEVICELIST_ANNOUNCE = 0x4441,
PAKID_CORE_DEVICE_REPLY = 0x6472,
PAKID_CORE_DEVICE_IOREQUEST = 0x4952,
PAKID_CORE_DEVICE_IOCOMPLETION = 0x4943,
PAKID_CORE_SERVER_CAPABILITY = 0x5350,
PAKID_CORE_CLIENT_CAPABILITY = 0x4350,
PAKID_CORE_DEVICELIST_REMOVE = 0x444D,
PAKID_PRN_CACHE_DATA = 0x5043,
PAKID_CORE_USER_LOGGEDON = 0x554C,
PAKID_PRN_USING_XPS = 0x5543,
}

pub const VERSION_MAJOR: u16 = 0x0001;
pub const VERSION_MINOR: u16 = 0x000c;

pub const SMARTCARD_CAPABILITY_VERSION_01: u32 = 0x00000001;
#[allow(dead_code)]
pub const GENERAL_CAPABILITY_VERSION_01: u32 = 0x00000001;
pub const GENERAL_CAPABILITY_VERSION_02: u32 = 0x00000002;

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum CapabilityType {
CAP_GENERAL_TYPE = 0x0001,
CAP_PRINTER_TYPE = 0x0002,
CAP_PORT_TYPE = 0x0003,
CAP_DRIVE_TYPE = 0x0004,
CAP_SMARTCARD_TYPE = 0x0005,
}

// If there were multiple redirected devices, they would need unique IDs. In our case there is only
// one permanent smartcard device, so we hardcode an ID 1.
pub const SCARD_DEVICE_ID: u32 = 1;

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum DeviceType {
RDPDR_DTYP_SERIAL = 0x00000001,
RDPDR_DTYP_PARALLEL = 0x00000002,
RDPDR_DTYP_PRINT = 0x00000004,
RDPDR_DTYP_FILESYSTEM = 0x00000008,
RDPDR_DTYP_SMARTCARD = 0x00000020,
}

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum MajorFunction {
IRP_MJ_CREATE = 0x00000000,
IRP_MJ_CLOSE = 0x00000002,
IRP_MJ_READ = 0x00000003,
IRP_MJ_WRITE = 0x00000004,
IRP_MJ_DEVICE_CONTROL = 0x0000000E,
IRP_MJ_QUERY_VOLUME_INFORMATION = 0x0000000A,
IRP_MJ_SET_VOLUME_INFORMATION = 0x0000000B,
IRP_MJ_QUERY_INFORMATION = 0x00000005,
IRP_MJ_SET_INFORMATION = 0x00000006,
IRP_MJ_DIRECTORY_CONTROL = 0x0000000C,
IRP_MJ_LOCK_CONTROL = 0x00000011,
}

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[allow(non_camel_case_types)]
pub enum MinorFunction {
IRP_MN_NONE = 0x00000000,
IRP_MN_QUERY_DIRECTORY = 0x00000001,
IRP_MN_NOTIFY_CHANGE_DIRECTORY = 0x00000002,
}
Loading

0 comments on commit fd750dd

Please sign in to comment.