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

Refactor rdpdr client #12750

Merged
merged 151 commits into from
Jun 25, 2022

Conversation

ibeckermayer
Copy link
Contributor

This is primarily a refactor. Before, all the logic for handling each major function was in the match statement in handle_device_io_request, now the relevant bit of code looks like

        match major_function {
            MajorFunction::IRP_MJ_DEVICE_CONTROL => {
                self.process_irp_device_control(device_io_request, payload)
            }
            MajorFunction::IRP_MJ_CREATE => self.process_irp_create(device_io_request, payload),
            MajorFunction::IRP_MJ_QUERY_INFORMATION => {
                self.process_irp_query_information(device_io_request, payload)
            }
            MajorFunction::IRP_MJ_CLOSE => self.process_irp_close(device_io_request),
            _ => Err(invalid_data_error(&format!(
                // TODO(isaiah): send back a not implemented response(?)
                "got unsupported major_function in DeviceIoRequest: {:?}",
                &major_function
            ))),
        }

with the bulk of the logic copied into the process_irp_*'s. Also adds some more consistent debugging logging.

Isaiah Becker-Mayer added 30 commits March 31, 2022 15:35
…and cliprdr::Client's have the vchan::Client as a field.
…o trigger it by right-clicking, however it isn't working. One reason is that the vchannel PDU header isn't being added (see rdpdr::encode_message for how that's added to other messages). Noticing that made me notice that there is another cliprdr function for breaking outgoing messages into chunks that should be refactored into vchan to do that work + add the necessary vchan headers. This is a checkpoint commit while I go attend to that.
…lient parses the DeviceCreateRequest that's immediately sent back
…ugh in most cases, no need to neurotically add every bit of the documentation text to the code itself
@ibeckermayer ibeckermayer mentioned this pull request Jun 13, 2022
Copy link
Collaborator

@zmb3 zmb3 left a comment

Choose a reason for hiding this comment

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

Approving as all of my comments are stylistic, but I hope you'll address them 😄

lib/srv/desktop/rdp/rdpclient/librdprs.h Show resolved Hide resolved
@@ -401,9 +401,13 @@ func (c *Client) start() {
}
case tdp.SharedDirectoryCreateResponse:
if c.cfg.AllowDirectorySharing {
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What error is this checking?

lib/srv/desktop/rdp/rdpclient/librdprs.h Outdated Show resolved Hide resolved
lib/srv/desktop/rdp/rdpclient/librdprs.h Outdated Show resolved Hide resolved
if res.fso.file_type == FileType::Directory {
if rdp_req.create_disposition == flags::CreateDisposition::FILE_CREATE {
// https://github.com/FreeRDP/FreeRDP/blob/511444a65e7aa2f537c5e531fa68157a50c1bd4d/channels/drive/client/drive_file.c#L221
// ERROR_ALREADY_EXISTS --> STATUS_OBJECT_NAME_COLLISION: https://github.com/FreeRDP/FreeRDP/blob/511444a65e7aa2f537c5e531fa68157a50c1bd4d/channels/drive/client/drive_main.c#L102
Copy link
Collaborator

Choose a reason for hiding this comment

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

What to these x --> y comments mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The line above them points to the corollary code in FreeRDP where x is set (as a FreeRDP-type error), and the line itself points to the code in RDP where x is converted to y, the actual RDP code that's sent by FreeRDP. Its basically documenting how I determined which NTSTATUS to send back. Probably unnecessary to leave in, deleted.

// If the file already exists, replace it with the given file. If it does not, create the given file.
} else if rdp_req.create_disposition == flags::CreateDisposition::FILE_OPEN {
// If the file already exists, open it instead of creating a new file. If it does not, fail the request and do not create a new file.
if res.err_code == TdpErrCode::Nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I tend to prefer match over a large if/else chain

@ibeckermayer ibeckermayer changed the base branch from isaiah/irp-mj-close to windows-desktop-directory-sharing June 24, 2022 19:58
@ibeckermayer ibeckermayer merged commit 41577e8 into windows-desktop-directory-sharing Jun 25, 2022
ibeckermayer pushed a commit that referenced this pull request Jul 6, 2022
ibeckermayer pushed a commit that referenced this pull request Jul 13, 2022
ibeckermayer pushed a commit that referenced this pull request Aug 23, 2022
* `IRP_MJ_CREATE` (#12665)

* `IRP_MJ_QUERY_INFORMATION` (#12717)

* `IRP_MJ_CLOSE` (#12729)

* Refactor rdpdr client (#12750)

* Adding logic for `FILE_SUPERSEDE` (#12829)

* Improve `process_irp_create` (#12830)

* adds return statements that got lost in a merge

* `IRP_MJ_DIRECTORY_CONTROL` (#12870)

* `FileFullDirectoryInformation` (#12908)

* Improve `ClientDriveQueryDirectoryResponse.encode()` (#12912)

* `IRP_MJ_QUERY_VOLUME_INFORMATION` (#13071)

* Fix Shared Directory Request handling when feature is disabled (#13439)

* IRP_MJ_READ, IRP_MJ_WRITE, and IRP_MJ_SET_INFORMATION (#13995)

* Adds constants for sizing calculations (#14051)

Co-authored-by: Łukasz Kozłowski <lukasz.kozlowski@goteleport.com>
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
ibeckermayer pushed a commit that referenced this pull request Aug 23, 2022
* `IRP_MJ_CREATE` (#12665)

* `IRP_MJ_QUERY_INFORMATION` (#12717)

* `IRP_MJ_CLOSE` (#12729)

* Refactor rdpdr client (#12750)

* Adding logic for `FILE_SUPERSEDE` (#12829)

* Improve `process_irp_create` (#12830)

* adds return statements that got lost in a merge

* `IRP_MJ_DIRECTORY_CONTROL` (#12870)

* `FileFullDirectoryInformation` (#12908)

* Improve `ClientDriveQueryDirectoryResponse.encode()` (#12912)

* `IRP_MJ_QUERY_VOLUME_INFORMATION` (#13071)

* Fix Shared Directory Request handling when feature is disabled (#13439)

* IRP_MJ_READ, IRP_MJ_WRITE, and IRP_MJ_SET_INFORMATION (#13995)

* Adds constants for sizing calculations (#14051)

Co-authored-by: Łukasz Kozłowski <lukasz.kozlowski@goteleport.com>
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
ibeckermayer pushed a commit that referenced this pull request Sep 7, 2022
…ring) (#15770)

* Windows Desktop Directory Sharing (#13630)

* `IRP_MJ_CREATE` (#12665)

* `IRP_MJ_QUERY_INFORMATION` (#12717)

* `IRP_MJ_CLOSE` (#12729)

* Refactor rdpdr client (#12750)

* Adding logic for `FILE_SUPERSEDE` (#12829)

* Improve `process_irp_create` (#12830)

* adds return statements that got lost in a merge

* `IRP_MJ_DIRECTORY_CONTROL` (#12870)

* `FileFullDirectoryInformation` (#12908)

* Improve `ClientDriveQueryDirectoryResponse.encode()` (#12912)

* `IRP_MJ_QUERY_VOLUME_INFORMATION` (#13071)

* Fix Shared Directory Request handling when feature is disabled (#13439)

* IRP_MJ_READ, IRP_MJ_WRITE, and IRP_MJ_SET_INFORMATION (#13995)

* Adds constants for sizing calculations (#14051)

Co-authored-by: Łukasz Kozłowski <lukasz.kozlowski@goteleport.com>
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* `UnixPath` and `WindowsPath` (#14267)

* `SharedDirectoryMoveRequest` and `SharedDirectoryMoveResponse` (#14959)

* `SharedDirectoryCreateResponse` update (#15289)

* Fix `process_irp_set_information` (#15364)

* Sanitize Rust Debug Logs (#15743)

* updates rdp-rs ref to include licensing changes

* Updates rdp-rs ref and fixes Cargo

Co-authored-by: Łukasz Kozłowski <lukasz.kozlowski@goteleport.com>
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants