From 3aa8096bc4e1c6c762f8553c516b5ce099ba5f71 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 29 Jul 2019 14:03:34 -0700 Subject: Fix scp_recv ABI issue on Windows * Adopt scp_recv2 instead, which uses compatible 64-bit stat types * Mark scp_recv as deprecated * small version bump Fixes https://github.com/alexcrichton/ssh2-rs/issues/109 Refs https://github.com/alexcrichton/ssh2-rs/pull/117 Co-authored-by: Joyce Babu --- libssh2-sys/Cargo.toml | 2 +- libssh2-sys/lib.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'libssh2-sys') diff --git a/libssh2-sys/Cargo.toml b/libssh2-sys/Cargo.toml index 4dc882a..06a7caa 100644 --- a/libssh2-sys/Cargo.toml +++ b/libssh2-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libssh2-sys" -version = "0.2.11" +version = "0.2.12" authors = ["Alex Crichton "] links = "ssh2" build = "build.rs" diff --git a/libssh2-sys/lib.rs b/libssh2-sys/lib.rs index e57864f..5ce1dc2 100644 --- a/libssh2-sys/lib.rs +++ b/libssh2-sys/lib.rs @@ -192,6 +192,24 @@ pub enum LIBSSH2_SFTP_HANDLE {} pub type libssh2_int64_t = i64; pub type libssh2_uint64_t = u64; +// libssh2_struct_stat is a typedef for libc::stat on all platforms, however, +// Windows has a bunch of legacy around struct stat that makes things more +// complicated to validate with systest. +// The most reasonable looking solution to this is a newtype that derefs +// to libc::stat. +// We cannot use `pub struct libssh2_struct_stat(pub libc::stat)` because +// that triggers a `no tuple structs in FFI` error. +#[repr(C)] +pub struct libssh2_struct_stat(libc::stat); + +impl std::ops::Deref for libssh2_struct_stat { + type Target = libc::stat; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + #[repr(C)] pub struct libssh2_agent_publickey { pub magic: c_uint, @@ -548,11 +566,19 @@ extern "C" { pub fn libssh2_knownhost_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_KNOWNHOSTS; // scp + #[deprecated(note = "dangerously unsafe on windows, use libssh2_scp_recv2 instead")] pub fn libssh2_scp_recv( sess: *mut LIBSSH2_SESSION, path: *const c_char, sb: *mut libc::stat, ) -> *mut LIBSSH2_CHANNEL; + + pub fn libssh2_scp_recv2( + sess: *mut LIBSSH2_SESSION, + path: *const c_char, + sb: *mut libssh2_struct_stat, + ) -> *mut LIBSSH2_CHANNEL; + pub fn libssh2_scp_send64( sess: *mut LIBSSH2_SESSION, path: *const c_char, -- cgit v1.2.3