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

IRP_MJ_DIRECTORY_CONTROL #12870

Merged
Merged
Show file tree
Hide file tree
Changes from 132 commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
24c1a90
Creates a general vchan Client that can read chunked messages. rdpdr …
Mar 31, 2022
41ac367
Tidying up
Mar 31, 2022
58cac52
Merge branch 'master' into isaiah/reuse-vchan-read
Mar 31, 2022
fa3531f
small fixes
Mar 31, 2022
ab4d66d
Merge branch 'master' into isaiah/reuse-vchan-read
Mar 31, 2022
aaa8369
fixes linting errors
Apr 1, 2022
54b7e3d
Merge branch 'master' into isaiah/reuse-vchan-read
Apr 1, 2022
071620b
Merge branch 'master' into isaiah/reuse-vchan-read
Apr 1, 2022
52a3d5d
Merge branch 'master' into isaiah/reuse-vchan-read
Apr 1, 2022
ceddf84
Adds drive redirection capability set to the Client Core Capability R…
Apr 1, 2022
6baccf6
Adds the ClientDeviceListAnnounce message, plus some prototype code t…
Apr 4, 2022
9036618
Adds to_unicode util
Apr 4, 2022
770f6e7
refactor of vchan and rdpdr to use it
Apr 4, 2022
17a35e8
refactors cliprdr to use generalized vchan header and chunking
Apr 4, 2022
c946b52
nits
Apr 4, 2022
787b67e
Merge branch 'master' into isaiah/reuse-vchan-write
Apr 4, 2022
6cd9ac2
small fixes from CR
Apr 4, 2022
997b7d6
Merge branch 'master' into isaiah/reuse-vchan-write
Apr 4, 2022
eb8ed1a
Merge branch 'isaiah/reuse-vchan-write' into isaiah/mock-drive-redire…
Apr 4, 2022
54b53d0
A right click sends an ClientDeviceListAnnounce message and the rdp c…
Apr 6, 2022
8f1ead3
adds prototype logic for handling IRP_MJ_QUERY_INFORMATION and IRP_MJ…
Apr 8, 2022
9a88738
removes some un needed comments. the link to the documentation is eno…
Apr 11, 2022
fb60ebb
Successfully mocks a drive for redirection
Apr 15, 2022
51f83e5
adding important todo
Apr 19, 2022
b4192a6
removes unneeded pub decl
Apr 25, 2022
6cf694a
refactors rdpdr into its own self-contained folder module
Apr 25, 2022
fa0d555
moving scard into rdpdr
Apr 26, 2022
4b9c330
allowing dead code
Apr 26, 2022
66eb895
stubs out request_file_info
Apr 26, 2022
687b84c
fixes mismatched declaration
Apr 27, 2022
058530b
completes IRP_MJ_DEVICE_CONTROL
Apr 27, 2022
1543585
adds a check for allow_directory_sharing so that we guarantee its fun…
Apr 27, 2022
549eb02
adds SharedDirectoryAnnounce and removes the right click hack from cl…
Apr 27, 2022
8c5e2b1
Adds SharedDirectoryAcknowledge tdp message, refactors rust-go interf…
Apr 28, 2022
de13b64
updates naming convention
Apr 28, 2022
8017ef2
Making sense of handle_client_id_confirm
Apr 28, 2022
1ce587f
finishes out shared directory ack
Apr 28, 2022
66b5b00
updates to new sd_acknowledge
Apr 29, 2022
de8e052
uses a struct for ack
Apr 30, 2022
0feae71
roadblock at 'static lifetime error
May 2, 2022
20d9aeb
refactors codebase to only contain shared directory announce and shar…
May 3, 2022
ec900b8
Merge branch 'master' into isaiah/tdp-sd-announce-ack
May 3, 2022
e43694b
Merge branch 'master' into isaiah/tdp-sd-announce-ack
May 3, 2022
95af26b
fixes function name typo
May 4, 2022
2adf291
checking in to go work on other stuff
May 6, 2022
eec39f5
rather than passing errors via C-strings, we pass them as integers wh…
May 6, 2022
c43d688
Merge branch 'master' into isaiah/cgo-err-code
May 6, 2022
a56236f
giving CGOErrCode explicit values
May 7, 2022
20efe3e
removing useless format
May 7, 2022
dac6c41
adding feature flag
May 9, 2022
6251502
adding #[allow(dead_code)]
May 9, 2022
2cb663d
Merge branch 'master' into isaiah/cgo-err-code
May 9, 2022
3615580
Merge branch 'isaiah/cgo-err-code' into isaiah/tdp-sd-announce-ack
May 9, 2022
7fe5b95
Debugf
May 9, 2022
9274c31
Merge branch 'master' into isaiah/cgo-err-code
May 9, 2022
7975209
Merge branch 'isaiah/cgo-err-code' into isaiah/tdp-sd-announce-ack
May 9, 2022
b0072f9
Merge branch 'isaiah/tdp-sd-announce-ack' into isaiah/stub-irp-mj-create
May 9, 2022
ce1c6c5
removing mentions of code side
May 9, 2022
1732e90
Merge branch 'isaiah/cgo-err-code' into isaiah/tdp-sd-announce-ack
May 9, 2022
6605005
Merge branch 'isaiah/tdp-sd-announce-ack' into isaiah/stub-irp-mj-create
May 9, 2022
224db3a
removing dangling CGO_OK
May 9, 2022
9ec0cba
making a mod.rs
May 9, 2022
ee34ddd
moving scard in rdpdr
May 9, 2022
dbedfc8
moves constants into consts.rs
May 9, 2022
df26b8f
Adds go build flags for directory sharing and some basic scaffolding …
May 9, 2022
e0bbfcf
Merge branch 'isaiah/shared-directory-build-flag' into isaiah/tdp-sd-…
May 9, 2022
eccab5a
Merge branch 'master' into isaiah/tdp-sd-announce-ack
May 9, 2022
51c956c
reverting e
May 9, 2022
8d532c8
Id to ID
May 10, 2022
750fe60
typo
May 10, 2022
f4959ee
proof of concept for calling the closures from golang. Checkpoing com…
May 11, 2022
e5d849e
trims rust back to bare minimum required for poc
May 11, 2022
f146e42
adds TypeSharedDirectoryAcknowledge, TypeSharedDirectoryInfoRequest, …
May 11, 2022
53cc341
Adds sharedDirectoryInfoRequest to go client
May 12, 2022
fe4bd3e
adds SharedDirectoryInfoResponse to go client
May 12, 2022
6bfc7a3
Merge branch 'isaiah/tdp-sd-announce-ack' into isaiah/rdp-tdp-transl-…
May 12, 2022
27d7c53
CR
May 12, 2022
f00eeb6
fixes compiler errors
May 12, 2022
0227339
Adds the straightforward failure modes
May 14, 2022
cd4b5a2
adds file_cache
May 14, 2022
9ebf970
adds Shared Directory Create Request
May 14, 2022
8d97123
adds Shared Directory Delete Request
May 15, 2022
034f396
fills out the rest of IRP_MJ_CREATE
May 15, 2022
b01c4ee
adds plumbing for calling handle_tdp_sd_create_response and handle_td…
May 15, 2022
d7950f6
adds logic for calling handle_tdp_sd_create_response and handle_tdp_s…
May 15, 2022
1db2ff5
reverting mistaken Makefile change
May 15, 2022
e1ce4ce
Merge branch 'isaiah/rdp-tdp-transl-arch' into isaiah/complete-irp-mj…
May 15, 2022
664a8e4
adds missing STATUS_SUCCESS messages
May 17, 2022
6ce109a
adds logic for IRP_MJ_QUERY_INFORMATION
May 17, 2022
3dc58ad
adding dead_code tag
May 17, 2022
90350d1
reverting Makefile
May 17, 2022
a71b390
Adds handling of IRP_MJ_CLOSE
May 17, 2022
c4371da
Merge branch 'master' into isaiah/tdp-sd-announce-ack
May 18, 2022
9e4db09
refactored all available, now realizing that I should've branched off…
May 18, 2022
511b1d2
Merge branch 'isaiah/irp-mj-close' into isaiah/irp-mj-refactor
May 18, 2022
02f3ec9
moves IRP_MJ_CLOSE handling into process_irp_close
May 18, 2022
750e7ff
fixing build bug and go lint errors
May 19, 2022
5bd7968
merging branch isaiah/tdp-sd-announce-ack
May 19, 2022
15fb5c5
Merge branch 'isaiah/rdp-tdp-transl-arch' into isaiah/complete-irp-mj…
May 19, 2022
efa9ac1
reverting Makefile
May 19, 2022
23ddd4d
Merge branch 'isaiah/complete-irp-mj-create' into isaiah/irp-mj-query…
May 19, 2022
67ee1b8
Merge branch 'isaiah/irp-mj-query-information' into isaiah/irp-mj-close
May 19, 2022
8e0a0ed
Merge branch 'isaiah/irp-mj-close' into isaiah/irp-mj-refactor
May 19, 2022
61d2509
Adds CGOTdpErrCode. Go behaves oddly with enums being placed in struc…
May 19, 2022
f6f7c69
I decided there's no need to use errCodeToTdpErrCode at all. We can j…
May 19, 2022
8dc6616
adding CGOFileType
May 19, 2022
57a826c
changed up the naming convention for these enums, since the primary r…
May 19, 2022
b449124
fixing rust linting problems
May 19, 2022
6b304ff
Merge branch 'isaiah/tdp-sd-announce-ack' into isaiah/rdp-tdp-transl-…
May 19, 2022
766c0ca
fixing clippy errors
May 19, 2022
93ba0bf
Merge branch 'isaiah/rdp-tdp-transl-arch' into isaiah/complete-irp-mj…
May 19, 2022
3c3db15
Fixes linting errors
May 19, 2022
570019a
Merge branch 'isaiah/complete-irp-mj-create' into isaiah/irp-mj-query…
May 19, 2022
58cf5e2
fixing lint errors and reverting Makefile
May 19, 2022
7155ef4
Merge branch 'isaiah/irp-mj-query-information' into isaiah/irp-mj-close
May 19, 2022
7e4986f
fixing clippy errors
May 19, 2022
cde94ea
Merge branch 'isaiah/irp-mj-close' into isaiah/irp-mj-refactor
May 19, 2022
bd86280
fixing clippy errors
May 19, 2022
1abfd00
fixing Makefile
May 20, 2022
0732269
adds SharedDirectoryListRequest, support for IRP_MJ_DIRECTORY_CONTROL…
May 23, 2022
ab54ef5
Adding logic for FILE_SUPERSEDE
May 23, 2022
5c4aedb
taking an opportunity to improve code quality of process_irp_create a…
May 23, 2022
6213cb1
adds go code for encoding/decoding SharedDirectoryListResponse
May 23, 2022
91c855e
adds all the glue for getting SharedDirectoryListResponse's from the …
May 23, 2022
cd0a76a
updating a comment
May 24, 2022
25315f0
Merge branch 'isaiah/add-FILE-SUPERSEDE' into isaiah/irp-mj-directory…
May 24, 2022
1f93760
Merge branch 'isaiah/irp-mj-create-refactor' into isaiah/irp-mj-direc…
May 24, 2022
2edf592
Adding more detailed safety blocks for rust functions called from Go
May 24, 2022
5ed8bd0
Adding algorithm explanation to the doc string of process_irp_directo…
May 24, 2022
7427ea9
changing a mistaken cli.prep_file_cache_fail_drive_query_dir_response…
May 24, 2022
5b8a8e6
Adds explanatory comment
May 24, 2022
7b97bcf
fixing fsoList cgo/ffi passing so that empty lists can be properly pa…
May 24, 2022
ea608cc
small changes from code review
Jun 1, 2022
d491636
noticed missing to_windows_time
Jun 1, 2022
8046597
Adds docstrings to new TDP types
Jun 14, 2022
9a9eb22
Merge branch 'windows-desktop-directory-sharing' into isaiah/add-FILE…
Jun 27, 2022
686633c
Merge branch 'isaiah/add-FILE-SUPERSEDE' into isaiah/irp-mj-create-re…
Jun 27, 2022
7718818
early return
Jun 27, 2022
aa1af3a
reintroducing match statement
Jun 27, 2022
37c3fbb
updating Cargo to latest rdp-rs head
Jun 27, 2022
f48195c
Merge branch 'isaiah/irp-mj-create-refactor' into isaiah/irp-mj-direc…
Jun 27, 2022
c07f3e5
Moves internal safety comments inside the function bodies, adds purpo…
Jun 28, 2022
405e2dc
remove incorrect apostrophes
Jun 28, 2022
7275216
removes handholding comments
Jun 28, 2022
3d60d06
removes comment that was converted to issue
Jun 28, 2022
1fba706
Merge branch 'windows-desktop-directory-sharing' into isaiah/irp-mj-d…
Jun 28, 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
12 changes: 11 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion e
Submodule e updated from b550ee to cf63aa
3 changes: 2 additions & 1 deletion lib/srv/desktop/rdp/rdpclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ num-traits = "0.2.14"
openssl = { version = "0.10.38", features = ["vendored"] }
rand = { version = "0.8.5", features = ["getrandom"] }
rand_chacha = "0.3.1"
rdp-rs = { git = "https://github.com/gravitational/rdp-rs", rev = "f51222e7edeaf2954e2c02db3506aa36e02304ca" }
rdp-rs = { git = "https://github.com/gravitational/rdp-rs", rev = "e0a659cd05edb13b64dd8735d7df59c61f1d39fa" }
ibeckermayer marked this conversation as resolved.
Show resolved Hide resolved
uuid = { version = "0.8.2", features = ["v4"] }
utf16string = "0.2.0"
218 changes: 205 additions & 13 deletions lib/srv/desktop/rdp/rdpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func (c *Client) start() {

// C.read_rdp_output blocks for the duration of the RDP connection and
// calls handle_bitmap repeatedly with the incoming bitmaps.
if err := C.read_rdp_output(c.rustClient); err != C.ErrCodeSuccess {
c.cfg.Log.Warningf("Failed reading RDP output frame: %v", err)
if errCode := C.read_rdp_output(c.rustClient); errCode != C.ErrCodeSuccess {
c.cfg.Log.Warningf("Failed reading RDP output frame: %v", errCode)

// close the TDP connection to the browser
// (without this the input streaming goroutine will hang
Expand Down Expand Up @@ -283,15 +283,15 @@ func (c *Client) start() {
switch m := msg.(type) {
case tdp.MouseMove:
mouseX, mouseY = m.X, m.Y
if err := C.write_rdp_pointer(
if errCode := C.write_rdp_pointer(
c.rustClient,
C.CGOMousePointerEvent{
x: C.uint16_t(m.X),
y: C.uint16_t(m.Y),
button: C.PointerButtonNone,
wheel: C.PointerWheelNone,
},
); err != C.ErrCodeSuccess {
); errCode != C.ErrCodeSuccess {
return
}
case tdp.MouseButton:
Expand All @@ -307,7 +307,7 @@ func (c *Client) start() {
default:
button = C.PointerButtonNone
}
if err := C.write_rdp_pointer(
if errCode := C.write_rdp_pointer(
c.rustClient,
C.CGOMousePointerEvent{
x: C.uint16_t(mouseX),
Expand All @@ -316,7 +316,7 @@ func (c *Client) start() {
down: m.State == tdp.ButtonPressed,
wheel: C.PointerWheelNone,
},
); err != C.ErrCodeSuccess {
); errCode != C.ErrCodeSuccess {
return
}
case tdp.MouseWheel:
Expand All @@ -335,7 +335,7 @@ func (c *Client) start() {
default:
wheel = C.PointerWheelNone
}
if err := C.write_rdp_pointer(
if errCode := C.write_rdp_pointer(
c.rustClient,
C.CGOMousePointerEvent{
x: C.uint16_t(mouseX),
Expand All @@ -344,31 +344,127 @@ func (c *Client) start() {
wheel: uint32(wheel),
wheel_delta: C.int16_t(m.Delta),
},
); err != C.ErrCodeSuccess {
); errCode != C.ErrCodeSuccess {
return
}
case tdp.KeyboardButton:
if err := C.write_rdp_keyboard(
if errCode := C.write_rdp_keyboard(
c.rustClient,
C.CGOKeyboardEvent{
code: C.uint16_t(m.KeyCode),
down: m.State == tdp.ButtonPressed,
},
); err != C.ErrCodeSuccess {
); errCode != C.ErrCodeSuccess {
return
}
case tdp.ClipboardData:
if len(m) > 0 {
if err := C.update_clipboard(
if errCode := C.update_clipboard(
c.rustClient,
(*C.uint8_t)(unsafe.Pointer(&m[0])),
C.uint32_t(len(m)),
); err != C.ErrCodeSuccess {
); errCode != C.ErrCodeSuccess {
return
}
} else {
c.cfg.Log.Warning("Recieved an empty clipboard message")
}
case tdp.SharedDirectoryAnnounce:
if c.cfg.AllowDirectorySharing {
driveName := C.CString(m.Name)
defer C.free(unsafe.Pointer(driveName))
if errCode := C.handle_tdp_sd_announce(c.rustClient, C.CGOSharedDirectoryAnnounce{
directory_id: C.uint32_t(m.DirectoryID),
name: driveName,
}); errCode != C.ErrCodeSuccess {
c.cfg.Log.Errorf("Device announce failed: %v", errCode)
return
}
}
case tdp.SharedDirectoryInfoResponse:
if c.cfg.AllowDirectorySharing {
path := C.CString(m.Fso.Path)
defer C.free(unsafe.Pointer(path))
if errCode := C.handle_tdp_sd_info_response(c.rustClient, C.CGOSharedDirectoryInfoResponse{
completion_id: C.uint32_t(m.CompletionID),
err_code: m.ErrCode,
fso: C.CGOFileSystemObject{
last_modified: C.uint64_t(m.Fso.LastModified),
size: C.uint64_t(m.Fso.Size),
file_type: m.Fso.FileType,
path: path,
},
}); errCode != C.ErrCodeSuccess {
c.cfg.Log.Errorf("SharedDirectoryInfoResponse failed: %v", errCode)
return
}
}
case tdp.SharedDirectoryCreateResponse:
if c.cfg.AllowDirectorySharing {
if err != nil {
c.cfg.Log.Errorf("SharedDirectoryCreateResponse failed: %v", err)
return
}
if errCode := C.handle_tdp_sd_create_response(c.rustClient, C.CGOSharedDirectoryCreateResponse{
completion_id: C.uint32_t(m.CompletionID),
err_code: m.ErrCode,
}); errCode != C.ErrCodeSuccess {
c.cfg.Log.Errorf("SharedDirectoryCreateResponse failed: %v", errCode)
return
}
}
case tdp.SharedDirectoryDeleteResponse:
if c.cfg.AllowDirectorySharing {
if errCode := C.handle_tdp_sd_delete_response(c.rustClient, C.CGOSharedDirectoryDeleteResponse{
completion_id: C.uint32_t(m.CompletionID),
err_code: m.ErrCode,
}); errCode != C.ErrCodeSuccess {
c.cfg.Log.Errorf("SharedDirectoryDeleteResponse failed: %v", errCode)
return
}
}
case tdp.SharedDirectoryListResponse:
if c.cfg.AllowDirectorySharing {
// fsoList is memory handled by Go, and will be freed
// by the garbage collector automatically sometime after
// this code block ends.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious the reasoning behind this comment. Any time you make a slice in Go the memory is handled by Go. Was there some reason we felt the need to clarify that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the first time I'd needed to pass something non-trivial across the FFI; this is basically me baby-talking myself through the memory management logic. It can be removed from the production code.

fsoList := make([]C.CGOFileSystemObject, 0, len(m.FsoList))

// For each FileSystemObject in FsoList, convert
// to a CGOFileSystemObject.
for _, fso := range m.FsoList {
path := C.CString(fso.Path)
// We create the CString, so its our responsibility
// to free it. It's handle_tdp_sd_list_response's responsibility
// to copy the memory pointed to it.
defer C.free(unsafe.Pointer(path))
fsoList = append(fsoList, C.CGOFileSystemObject{
last_modified: C.uint64_t(fso.LastModified),
size: C.uint64_t(fso.Size),
file_type: fso.FileType,
path: path,
})
}

fsoListLen := len(fsoList)
var cgoFsoList *C.CGOFileSystemObject

if fsoListLen > 0 {
cgoFsoList = (*C.CGOFileSystemObject)(unsafe.Pointer(&fsoList[0]))
} else {
cgoFsoList = (*C.CGOFileSystemObject)(unsafe.Pointer(&fsoList))
}

if errCode := C.handle_tdp_sd_list_response(c.rustClient, C.CGOSharedDirectoryListResponse{
completion_id: C.uint32_t(m.CompletionID),
err_code: m.ErrCode,
fso_list_length: C.uint32_t(fsoListLen),
fso_list: cgoFsoList,
}); errCode != C.ErrCodeSuccess {
c.cfg.Log.Errorf("SharedDirectoryListResponse failed: %v", errCode)
return
}
}
default:
c.cfg.Log.Warningf("Skipping unimplemented TDP message type %T", msg)
}
Expand Down Expand Up @@ -434,6 +530,102 @@ func (c *Client) handleRemoteCopy(data []byte) C.CGOErrCode {
return C.ErrCodeSuccess
}

//export tdp_sd_acknowledge
func tdp_sd_acknowledge(handle C.uintptr_t, ack *C.CGOSharedDirectoryAcknowledge) C.CGOErrCode {
return cgo.Handle(handle).Value().(*Client).sharedDirectoryAcknowledge(tdp.SharedDirectoryAcknowledge{
ErrCode: uint32(ack.err_code),
DirectoryID: uint32(ack.directory_id),
})
}

func (c *Client) sharedDirectoryAcknowledge(ack tdp.SharedDirectoryAcknowledge) C.CGOErrCode {
if c.cfg.AllowDirectorySharing {
if err := c.cfg.Conn.OutputMessage(ack); err != nil {
c.cfg.Log.Errorf("failed to send SharedDirectoryAcknowledge: %v", err)
return C.ErrCodeFailure
}
}
return C.ErrCodeSuccess
}

//export tdp_sd_info_request
func tdp_sd_info_request(handle C.uintptr_t, req *C.CGOSharedDirectoryInfoRequest) C.CGOErrCode {
return cgo.Handle(handle).Value().(*Client).sharedDirectoryInfoRequest(tdp.SharedDirectoryInfoRequest{
CompletionID: uint32(req.completion_id),
DirectoryID: uint32(req.directory_id),
Path: C.GoString(req.path),
})
}

func (c *Client) sharedDirectoryInfoRequest(req tdp.SharedDirectoryInfoRequest) C.CGOErrCode {
if c.cfg.AllowDirectorySharing {
if err := c.cfg.Conn.OutputMessage(req); err != nil {
c.cfg.Log.Errorf("failed to send SharedDirectoryAcknowledge: %v", err)
return C.ErrCodeFailure
}
}
return C.ErrCodeSuccess
}

//export tdp_sd_create_request
func tdp_sd_create_request(handle C.uintptr_t, req *C.CGOSharedDirectoryCreateRequest) C.CGOErrCode {
return cgo.Handle(handle).Value().(*Client).sharedDirectoryCreateRequest(tdp.SharedDirectoryCreateRequest{
CompletionID: uint32(req.completion_id),
DirectoryID: uint32(req.directory_id),
FileType: uint32(req.file_type),
Path: C.GoString(req.path),
})
}

func (c *Client) sharedDirectoryCreateRequest(req tdp.SharedDirectoryCreateRequest) C.CGOErrCode {
if c.cfg.AllowDirectorySharing {
if err := c.cfg.Conn.OutputMessage(req); err != nil {
c.cfg.Log.Errorf("failed to send SharedDirectoryAcknowledge: %v", err)
return C.ErrCodeFailure
}
}
return C.ErrCodeSuccess
}

//export tdp_sd_delete_request
func tdp_sd_delete_request(handle C.uintptr_t, req *C.CGOSharedDirectoryDeleteRequest) C.CGOErrCode {
return cgo.Handle(handle).Value().(*Client).sharedDirectoryDeleteRequest(tdp.SharedDirectoryDeleteRequest{
CompletionID: uint32(req.completion_id),
DirectoryID: uint32(req.directory_id),
Path: C.GoString(req.path),
})
}

func (c *Client) sharedDirectoryDeleteRequest(req tdp.SharedDirectoryDeleteRequest) C.CGOErrCode {
if c.cfg.AllowDirectorySharing {
if err := c.cfg.Conn.OutputMessage(req); err != nil {
c.cfg.Log.Errorf("failed to send SharedDirectoryAcknowledge: %v", err)
return C.ErrCodeFailure
}
}
return C.ErrCodeSuccess
}

//export tdp_sd_list_request
func tdp_sd_list_request(handle C.uintptr_t, req *C.CGOSharedDirectoryListRequest) C.CGOErrCode {
// TODO(isaiah): WRONG
ibeckermayer marked this conversation as resolved.
Show resolved Hide resolved
return cgo.Handle(handle).Value().(*Client).sharedDirectoryListRequest(tdp.SharedDirectoryListRequest{
CompletionID: uint32(req.completion_id),
DirectoryID: uint32(req.directory_id),
Path: C.GoString(req.path),
})
}

func (c *Client) sharedDirectoryListRequest(req tdp.SharedDirectoryListRequest) C.CGOErrCode {
if c.cfg.AllowDirectorySharing {
if err := c.cfg.Conn.OutputMessage(req); err != nil {
c.cfg.Log.Errorf("failed to send SharedDirectoryAcknowledge: %v", err)
return C.ErrCodeFailure
}
}
return C.ErrCodeSuccess
}

// Wait blocks until the client disconnects and runs the cleanup.
func (c *Client) Wait() error {
c.wg.Wait()
Expand All @@ -449,7 +641,7 @@ func (c *Client) Close() {
c.closeOnce.Do(func() {
c.handle.Delete()

if err := C.close_rdp(c.rustClient); err != C.ErrCodeSuccess {
if errCode := C.close_rdp(c.rustClient); errCode != C.ErrCodeSuccess {
c.cfg.Log.Warningf("failed to close the RDP client")
}
})
Expand Down
Loading