-
Notifications
You must be signed in to change notification settings - Fork 822
[sftp] Add encapsulated SftpSession type #5029
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
14b8204
[sftp] Add an empty SftpServerSession
ricab e0969bf
[sftp] Add SftpServerSession factory to session
ricab 359ed3a
[ssh] Add borrow_channel to PlainSSHProcess
ricab 4077ddd
[ssh] Reorder methods slightly
ricab cc12b44
[sftp] Add PlainSftpServerSession skeleton
ricab f62368f
[ssh] Make concrete sftp session
ricab aa1b4ac
[sftp] Adjust interface constructor visibility
ricab 01b5d24
[ssh] Adjust interface ctor visibility
ricab da9c5e5
[ssh] Consume an SSHSession to make an SFTP one
ricab 2e7f200
[cosmetic] Tweak namespace qualifications
ricab 48757e6
[ssh] Add a method to borrow the libssh session
ricab d212d92
[ssh] Prevent PlainSSHSession chopping with final
ricab 5fa0e67
[sftp] Prevent copy/move of the sftp session
ricab dc24cbb
[sftp] Borrow ssh session to create sftp session
ricab bbbdd99
[sftp] Copy and use sftp server init code
ricab 25b5d96
[sftp] Convert helper to private static
ricab c810319
[sftp] Rename field to avoid shadowing
ricab a5aeb03
[sftp] Create sshfs process and borrow channel
ricab 982d0af
[ssh] Add an exec_plain version to PlainSSHSession
ricab b7bc460
[sftp] Remove "Server" from "SftpSession" types
ricab 88a4525
[ssh] Avoid shadowing libssh types
ricab 76961e4
[sftp] Parameterize sftp session with sshfs cmd
ricab 9d2954d
[sftp] Handle failure to create raw sftp_server
ricab 39e77db
[sftp] Add TODO to use SftpMessage and avoid leak
ricab b1c78dc
[cmake] Avoid leaking libssh-specific definition
ricab f1a57c4
[ssh] Clarify not-moved pre-condition to borrow
ricab e598cc4
[sftp] Fix format post rebase
ricab f4a4471
[sftp] Add some TODOs to go through MP_LIBSSH
ricab 55bc87e
[tests] Test PlainSSHSession::exec_plain
ricab 4641aa5
[tests] Add a couple more tests for exec_plain
ricab a0b9ba3
[tests] Verify PlainSSHSession moving
ricab 1847386
[tests] Check SftpSessions' type traits
ricab 162fa66
[tests] Check SSHSession consumed to make Sftp one
ricab 6359c04
[tests] Rename mock libssh
ricab 2e63a7a
[tests] Test SftpSession runs sshfs command
ricab 45b2e85
[tests] Test Sftp session throws sshfs error
ricab 3335dcc
[tests] Test consumed session released once
ricab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright (C) Canonical, Ltd. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; version 3. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <multipass/private_pass_provider.h> | ||
| #include <multipass/ssh/plain_ssh_process.h> | ||
| #include <multipass/ssh/plain_ssh_session.h> | ||
| #include <multipass/sshfs_mount/sftp_session.h> | ||
|
|
||
| #include <libssh/sftp.h> // TODO@sftp avoid this include (need to go through MP_LIBSSH) | ||
|
|
||
| namespace multipass | ||
| { | ||
|
|
||
| /** | ||
| * A concrete SftpSession backed by an SSHFS mount: it serves the SFTP protocol over an SSH | ||
| * session to a remote sshfs client, which mounts it on the guest. | ||
| */ | ||
| class PlainSftpSession : public SftpSession, public PrivatePassProvider<PlainSftpSession> | ||
| { | ||
| public: | ||
| PlainSftpSession(PlainSSHSession&& ssh_session_obj, const std::string& sshfs_cmd); | ||
| PlainSftpSession(const PlainSftpSession&) = delete; | ||
| PlainSftpSession& operator=(const PlainSftpSession&) = delete; | ||
|
|
||
| // TODO@sftp Make class final before enabling these | ||
| PlainSftpSession(PlainSftpSession&&) = delete; | ||
| PlainSftpSession& operator=(PlainSftpSession&&) = delete; | ||
|
|
||
| private: | ||
| // TODO@sftp avoid mentioning sftp_server_free here (need to go through MP_LIBSSH) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem |
||
| using RawSftpSessionUptr = std::unique_ptr<sftp_session_struct, decltype(sftp_server_free)*>; | ||
|
|
||
| static RawSftpSessionUptr make_raw_sftp_session(ssh_session raw_session, ssh_channel channel); | ||
|
|
||
| PlainSSHSession plain_ssh_session; | ||
| std::unique_ptr<PlainSSHProcess> sshfs_process; | ||
| RawSftpSessionUptr raw_sftp_session; | ||
| }; | ||
| } // namespace multipass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright (C) Canonical, Ltd. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; version 3. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| namespace multipass | ||
| { | ||
| /** | ||
| * A server-side SFTP session. | ||
| */ | ||
| class SftpSession | ||
| { | ||
| public: | ||
| virtual ~SftpSession() = default; | ||
|
|
||
| // No copies | ||
| SftpSession(const SftpSession&) = delete; | ||
| SftpSession& operator=(const SftpSession&) = delete; | ||
|
|
||
| protected: | ||
| SftpSession() = default; | ||
| }; | ||
| } // namespace multipass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #5030 (I had already removed this inm there before I rebased on MP_LIBSSH, so leaving it to that PR).