From e9ac51eee7070a4d2917a03260a83180e312726d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 22 Feb 2020 08:22:02 -0800 Subject: Add Channel::request_auth_agent_forwarding This method enables agent forwarding --- Cargo.toml | 4 ++-- libssh2-sys/Cargo.toml | 2 +- libssh2-sys/lib.rs | 1 + src/channel.rs | 14 ++++++++++++++ tests/all/channel.rs | 16 ++++++++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ad883b5..c5c21f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ssh2" -version = "0.7.1" +version = "0.8.0" authors = ["Alex Crichton ", "Wez Furlong "] 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 ", "Wez Furlong "] 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 @@ -44,6 +44,22 @@ fn smoke() { assert!(channel.eof()); } +#[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(); -- cgit v1.2.3