Skip to content

Commit

Permalink
IRP_MJ_DIRECTORY_CONTROL (#12870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Becker-Mayer authored Jun 28, 2022
1 parent df484c9 commit 05b7574
Show file tree
Hide file tree
Showing 8 changed files with 922 additions and 140 deletions.
99 changes: 53 additions & 46 deletions 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 lib/srv/desktop/rdp/rdpclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ num-traits = "0.2.15"
rand = { version = "0.8.5", features = ["getrandom"] }
rand_chacha = "0.3.1"
rsa = "0.6.1"
rdp-rs = { git = "https://github.com/gravitational/rdp-rs", rev = "17ec446ecb73c58b77ac47c6fc8598153f673076" }
rdp-rs = { git = "https://github.com/gravitational/rdp-rs", rev = "6e4623bd6939759e6bdd32a9806cd2579a3b5d8f" }
uuid = { version = "1.1.2", features = ["v4"] }
utf16string = "0.2.0"

54 changes: 54 additions & 0 deletions lib/srv/desktop/rdp/rdpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,41 @@ func (c *Client) start() {
return
}
}
case tdp.SharedDirectoryListResponse:
if c.cfg.AllowDirectorySharing {
fsoList := make([]C.CGOFileSystemObject, 0, len(m.FsoList))

for _, fso := range m.FsoList {
path := C.CString(fso.Path)
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 @@ -574,6 +609,25 @@ func (c *Client) sharedDirectoryDeleteRequest(req tdp.SharedDirectoryDeleteReque
return C.ErrCodeSuccess
}

//export tdp_sd_list_request
func tdp_sd_list_request(handle C.uintptr_t, req *C.CGOSharedDirectoryListRequest) C.CGOErrCode {
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
}

// close frees the memory of the cgo.Handle,
// closes the RDP client connection,
// and frees the Rust client.
Expand Down
Loading

0 comments on commit 05b7574

Please sign in to comment.