diff options
author | Wez Furlong <wez@wezfurlong.org> | 2020-02-22 08:22:02 -0800 |
---|---|---|
committer | Wez Furlong <wez@wezfurlong.org> | 2020-02-22 08:32:26 -0800 |
commit | e9ac51eee7070a4d2917a03260a83180e312726d (patch) | |
tree | 9657a488c7aab4f71827227c1706b423032fcf7d | |
parent | 057083ebfd9b422d71bd6c836037e34072bcd32b (diff) | |
download | ssh2-rs-e9ac51eee7070a4d2917a03260a83180e312726d.zip |
Add Channel::request_auth_agent_forwarding
This method enables agent forwarding
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | libssh2-sys/Cargo.toml | 2 | ||||
-rw-r--r-- | libssh2-sys/lib.rs | 1 | ||||
-rw-r--r-- | src/channel.rs | 14 | ||||
-rw-r--r-- | tests/all/channel.rs | 16 |
5 files changed, 34 insertions, 3 deletions
@@ -1,6 +1,6 @@ [package] name = "ssh2" -version = "0.7.1" +version = "0.8.0" authors = ["Alex Crichton <alex@alexcrichton.com>", "Wez Furlong <wez@wezfurlong.org>"] license = "MIT/Apache-2.0" keywords = ["ssh"] @@ -19,7 +19,7 @@ vendored-openssl = ["libssh2-sys/vendored-openssl"] [dependencies] bitflags = "1.2" libc = "0.2" -libssh2-sys = { path = "libssh2-sys", version = "0.2.14" } +libssh2-sys = { path = "libssh2-sys", version = "0.2.15" } parking_lot = "0.10" [dev-dependencies] diff --git a/libssh2-sys/Cargo.toml b/libssh2-sys/Cargo.toml index 3a281f1..ba06024 100644 --- a/libssh2-sys/Cargo.toml +++ b/libssh2-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libssh2-sys" -version = "0.2.14" +version = "0.2.15" authors = ["Alex Crichton <alex@alexcrichton.com>", "Wez Furlong <wez@wezfurlong.org>"] links = "ssh2" build = "build.rs" diff --git a/libssh2-sys/lib.rs b/libssh2-sys/lib.rs index 0017781..d1f6767 100644 --- a/libssh2-sys/lib.rs +++ b/libssh2-sys/lib.rs @@ -490,6 +490,7 @@ extern "C" { channel: *mut LIBSSH2_CHANNEL, mode: c_int, ) -> c_int; + pub fn libssh2_channel_request_auth_agent(channel: *mut LIBSSH2_CHANNEL) -> c_int; // userauth pub fn libssh2_userauth_authenticated(sess: *mut LIBSSH2_SESSION) -> c_int; diff --git a/src/channel.rs b/src/channel.rs index 82ac981..00a9493 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -204,6 +204,20 @@ impl Channel { }) } + /// Requests that the remote host start an authentication agent; + /// if successful requests to that agent will be forwarded from + /// the server back to the local authentication agent on the client side. + /// + /// Note that some hosts are configured to disallow agent forwarding, + /// and that even if enabled, there is a possibility that starting + /// the agent on the remote system can fail. + pub fn request_auth_agent_forwarding(&mut self) -> Result<(), Error> { + let locked = self.lock(); + locked + .sess + .rc(unsafe { raw::libssh2_channel_request_auth_agent(locked.raw) }) + } + /// Execute a command /// /// An execution is one of the standard process services defined by the SSH2 diff --git a/tests/all/channel.rs b/tests/all/channel.rs index 2f14d01..75ece4e 100644 --- a/tests/all/channel.rs +++ b/tests/all/channel.rs @@ -45,6 +45,22 @@ fn smoke() { } #[test] +fn agent_forward() { + let sess = ::authed_session(); + let mut channel = sess.channel_session().unwrap(); + channel.request_auth_agent_forwarding().unwrap(); + channel.exec("echo $SSH_AUTH_SOCK").unwrap(); + + let (output, _) = consume_stdio(&mut channel); + let output = output.trim(); + // make sure that the sock is set + assert_ne!(output, ""); + // and that it isn't just inherited the one we set for this + // test environment + assert_ne!(output, std::env::var("SSH_AUTH_SOCK").unwrap()); +} + +#[test] fn bad_smoke() { let sess = ::authed_session(); let mut channel = sess.channel_session().unwrap(); |