libssh2_sys/
lib.rs

1#![doc(html_root_url = "http://alexcrichton.com/ssh2-rs")]
2#![allow(bad_style)]
3#![allow(unused_extern_crates)]
4
5extern crate libc;
6
7extern crate libz_sys;
8#[cfg(unix)]
9extern crate openssl_sys;
10
11use libc::ssize_t;
12use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void, size_t};
13
14pub const SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT: c_int = 1;
15pub const SSH_DISCONNECT_PROTOCOL_ERROR: c_int = 2;
16pub const SSH_DISCONNECT_KEY_EXCHANGE_FAILED: c_int = 3;
17pub const SSH_DISCONNECT_RESERVED: c_int = 4;
18pub const SSH_DISCONNECT_MAC_ERROR: c_int = 5;
19pub const SSH_DISCONNECT_COMPRESSION_ERROR: c_int = 6;
20pub const SSH_DISCONNECT_SERVICE_NOT_AVAILABLE: c_int = 7;
21pub const SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED: c_int = 8;
22pub const SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE: c_int = 9;
23pub const SSH_DISCONNECT_CONNECTION_LOST: c_int = 10;
24pub const SSH_DISCONNECT_BY_APPLICATION: c_int = 11;
25pub const SSH_DISCONNECT_TOO_MANY_CONNECTIONS: c_int = 12;
26pub const SSH_DISCONNECT_AUTH_CANCELLED_BY_USER: c_int = 13;
27pub const SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE: c_int = 14;
28pub const SSH_DISCONNECT_ILLEGAL_USER_NAME: c_int = 15;
29
30pub const LIBSSH2_FLAG_SIGPIPE: c_int = 1;
31pub const LIBSSH2_FLAG_COMPRESS: c_int = 2;
32
33pub const LIBSSH2_HOSTKEY_TYPE_UNKNOWN: c_int = 0;
34pub const LIBSSH2_HOSTKEY_TYPE_RSA: c_int = 1;
35pub const LIBSSH2_HOSTKEY_TYPE_DSS: c_int = 2;
36pub const LIBSSH2_HOSTKEY_TYPE_ECDSA_256: c_int = 3;
37pub const LIBSSH2_HOSTKEY_TYPE_ECDSA_384: c_int = 4;
38pub const LIBSSH2_HOSTKEY_TYPE_ECDSA_521: c_int = 5;
39pub const LIBSSH2_HOSTKEY_TYPE_ED25519: c_int = 6;
40
41pub const LIBSSH2_METHOD_KEX: c_int = 0;
42pub const LIBSSH2_METHOD_HOSTKEY: c_int = 1;
43pub const LIBSSH2_METHOD_CRYPT_CS: c_int = 2;
44pub const LIBSSH2_METHOD_CRYPT_SC: c_int = 3;
45pub const LIBSSH2_METHOD_MAC_CS: c_int = 4;
46pub const LIBSSH2_METHOD_MAC_SC: c_int = 5;
47pub const LIBSSH2_METHOD_COMP_CS: c_int = 6;
48pub const LIBSSH2_METHOD_COMP_SC: c_int = 7;
49pub const LIBSSH2_METHOD_LANG_CS: c_int = 8;
50pub const LIBSSH2_METHOD_LANG_SC: c_int = 9;
51pub const LIBSSH2_METHOD_SIGN_ALGO: c_int = 10;
52
53pub const LIBSSH2_CHANNEL_PACKET_DEFAULT: c_uint = 32768;
54pub const LIBSSH2_CHANNEL_WINDOW_DEFAULT: c_uint = 2 * 1024 * 1024;
55
56pub const LIBSSH2_ERROR_BANNER_RECV: c_int = -2;
57pub const LIBSSH2_ERROR_BANNER_SEND: c_int = -3;
58pub const LIBSSH2_ERROR_INVALID_MAC: c_int = -4;
59pub const LIBSSH2_ERROR_KEX_FAILURE: c_int = -5;
60pub const LIBSSH2_ERROR_ALLOC: c_int = -6;
61pub const LIBSSH2_ERROR_SOCKET_SEND: c_int = -7;
62pub const LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE: c_int = -8;
63pub const LIBSSH2_ERROR_TIMEOUT: c_int = -9;
64pub const LIBSSH2_ERROR_HOSTKEY_INIT: c_int = -10;
65pub const LIBSSH2_ERROR_HOSTKEY_SIGN: c_int = -11;
66pub const LIBSSH2_ERROR_DECRYPT: c_int = -12;
67pub const LIBSSH2_ERROR_SOCKET_DISCONNECT: c_int = -13;
68pub const LIBSSH2_ERROR_PROTO: c_int = -14;
69pub const LIBSSH2_ERROR_PASSWORD_EXPIRED: c_int = -15;
70pub const LIBSSH2_ERROR_FILE: c_int = -16;
71pub const LIBSSH2_ERROR_METHOD_NONE: c_int = -17;
72pub const LIBSSH2_ERROR_AUTHENTICATION_FAILED: c_int = -18;
73pub const LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: c_int = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
74pub const LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED: c_int = -19;
75pub const LIBSSH2_ERROR_CHANNEL_OUTOFORDER: c_int = -20;
76pub const LIBSSH2_ERROR_CHANNEL_FAILURE: c_int = -21;
77pub const LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED: c_int = -22;
78pub const LIBSSH2_ERROR_CHANNEL_UNKNOWN: c_int = -23;
79pub const LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED: c_int = -24;
80pub const LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED: c_int = -25;
81pub const LIBSSH2_ERROR_CHANNEL_CLOSED: c_int = -26;
82pub const LIBSSH2_ERROR_CHANNEL_EOF_SENT: c_int = -27;
83pub const LIBSSH2_ERROR_SCP_PROTOCOL: c_int = -28;
84pub const LIBSSH2_ERROR_ZLIB: c_int = -29;
85pub const LIBSSH2_ERROR_SOCKET_TIMEOUT: c_int = -30;
86pub const LIBSSH2_ERROR_SFTP_PROTOCOL: c_int = -31;
87pub const LIBSSH2_ERROR_REQUEST_DENIED: c_int = -32;
88pub const LIBSSH2_ERROR_METHOD_NOT_SUPPORTED: c_int = -33;
89pub const LIBSSH2_ERROR_INVAL: c_int = -34;
90pub const LIBSSH2_ERROR_INVALID_POLL_TYPE: c_int = -35;
91pub const LIBSSH2_ERROR_PUBLICKEY_PROTOCOL: c_int = -36;
92pub const LIBSSH2_ERROR_EAGAIN: c_int = -37;
93pub const LIBSSH2_ERROR_BUFFER_TOO_SMALL: c_int = -38;
94pub const LIBSSH2_ERROR_BAD_USE: c_int = -39;
95pub const LIBSSH2_ERROR_COMPRESS: c_int = -40;
96pub const LIBSSH2_ERROR_OUT_OF_BOUNDARY: c_int = -41;
97pub const LIBSSH2_ERROR_AGENT_PROTOCOL: c_int = -42;
98pub const LIBSSH2_ERROR_SOCKET_RECV: c_int = -43;
99pub const LIBSSH2_ERROR_ENCRYPT: c_int = -44;
100pub const LIBSSH2_ERROR_BAD_SOCKET: c_int = -45;
101pub const LIBSSH2_ERROR_KNOWN_HOSTS: c_int = -46;
102pub const LIBSSH2_ERROR_CHANNEL_WINDOW_FULL: c_int = -47;
103pub const LIBSSH2_ERROR_KEYFILE_AUTH_FAILED: c_int = -48;
104pub const LIBSSH2_ERROR_RANDGEN: c_int = -49;
105pub const LIBSSH2_ERROR_MISSING_USERAUTH_BANNER: c_int = -50;
106pub const LIBSSH2_ERROR_ALGO_UNSUPPORTED: c_int = -51;
107
108pub const LIBSSH2_FX_EOF: c_int = 1;
109pub const LIBSSH2_FX_NO_SUCH_FILE: c_int = 2;
110pub const LIBSSH2_FX_PERMISSION_DENIED: c_int = 3;
111pub const LIBSSH2_FX_FAILURE: c_int = 4;
112pub const LIBSSH2_FX_BAD_MESSAGE: c_int = 5;
113pub const LIBSSH2_FX_NO_CONNECTION: c_int = 6;
114pub const LIBSSH2_FX_CONNECTION_LOST: c_int = 7;
115pub const LIBSSH2_FX_OP_UNSUPPORTED: c_int = 8;
116pub const LIBSSH2_FX_INVALID_HANDLE: c_int = 9;
117pub const LIBSSH2_FX_NO_SUCH_PATH: c_int = 10;
118pub const LIBSSH2_FX_FILE_ALREADY_EXISTS: c_int = 11;
119pub const LIBSSH2_FX_WRITE_PROTECT: c_int = 12;
120pub const LIBSSH2_FX_NO_MEDIA: c_int = 13;
121pub const LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: c_int = 14;
122pub const LIBSSH2_FX_QUOTA_EXCEEDED: c_int = 15;
123pub const LIBSSH2_FX_UNKNOWN_PRINCIPAL: c_int = 16;
124pub const LIBSSH2_FX_LOCK_CONFLICT: c_int = 17;
125pub const LIBSSH2_FX_DIR_NOT_EMPTY: c_int = 18;
126pub const LIBSSH2_FX_NOT_A_DIRECTORY: c_int = 19;
127pub const LIBSSH2_FX_INVALID_FILENAME: c_int = 20;
128pub const LIBSSH2_FX_LINK_LOOP: c_int = 21;
129
130pub const LIBSSH2_HOSTKEY_HASH_MD5: c_int = 1;
131pub const LIBSSH2_HOSTKEY_HASH_SHA1: c_int = 2;
132pub const LIBSSH2_HOSTKEY_HASH_SHA256: c_int = 3;
133
134pub const LIBSSH2_KNOWNHOST_FILE_OPENSSH: c_int = 1;
135
136pub const LIBSSH2_KNOWNHOST_CHECK_MATCH: c_int = 0;
137pub const LIBSSH2_KNOWNHOST_CHECK_MISMATCH: c_int = 1;
138pub const LIBSSH2_KNOWNHOST_CHECK_NOTFOUND: c_int = 2;
139pub const LIBSSH2_KNOWNHOST_CHECK_FAILURE: c_int = 3;
140
141pub const LIBSSH2_KNOWNHOST_TYPE_PLAIN: c_int = 1;
142pub const LIBSSH2_KNOWNHOST_TYPE_SHA1: c_int = 2;
143pub const LIBSSH2_KNOWNHOST_TYPE_CUSTOM: c_int = 3;
144pub const LIBSSH2_KNOWNHOST_KEYENC_RAW: c_int = 1 << 16;
145pub const LIBSSH2_KNOWNHOST_KEYENC_BASE64: c_int = 2 << 16;
146pub const LIBSSH2_KNOWNHOST_KEY_RSA1: c_int = 1 << 18;
147pub const LIBSSH2_KNOWNHOST_KEY_SSHRSA: c_int = 2 << 18;
148pub const LIBSSH2_KNOWNHOST_KEY_SSHDSS: c_int = 3 << 18;
149pub const LIBSSH2_KNOWNHOST_KEY_ECDSA_256: c_int = 4 << 18;
150pub const LIBSSH2_KNOWNHOST_KEY_ECDSA_384: c_int = 5 << 18;
151pub const LIBSSH2_KNOWNHOST_KEY_ECDSA_521: c_int = 6 << 18;
152pub const LIBSSH2_KNOWNHOST_KEY_ED25519: c_int = 7 << 18;
153pub const LIBSSH2_KNOWNHOST_KEY_UNKNOWN: c_int = 15 << 18;
154
155pub const LIBSSH2_FXF_READ: c_ulong = 0x00000001;
156pub const LIBSSH2_FXF_WRITE: c_ulong = 0x00000002;
157pub const LIBSSH2_FXF_APPEND: c_ulong = 0x00000004;
158pub const LIBSSH2_FXF_CREAT: c_ulong = 0x00000008;
159pub const LIBSSH2_FXF_TRUNC: c_ulong = 0x00000010;
160pub const LIBSSH2_FXF_EXCL: c_ulong = 0x00000020;
161
162pub const LIBSSH2_SFTP_OPENFILE: c_int = 0;
163pub const LIBSSH2_SFTP_OPENDIR: c_int = 1;
164
165pub const LIBSSH2_SFTP_ATTR_SIZE: c_ulong = 0x00000001;
166pub const LIBSSH2_SFTP_ATTR_UIDGID: c_ulong = 0x00000002;
167pub const LIBSSH2_SFTP_ATTR_PERMISSIONS: c_ulong = 0x00000004;
168pub const LIBSSH2_SFTP_ATTR_ACMODTIME: c_ulong = 0x00000008;
169pub const LIBSSH2_SFTP_ATTR_EXTENDED: c_ulong = 0x80000000;
170
171pub const LIBSSH2_SFTP_STAT: c_int = 0;
172pub const LIBSSH2_SFTP_LSTAT: c_int = 1;
173pub const LIBSSH2_SFTP_SETSTAT: c_int = 2;
174
175pub const LIBSSH2_SFTP_SYMLINK: c_int = 0;
176pub const LIBSSH2_SFTP_READLINK: c_int = 1;
177pub const LIBSSH2_SFTP_REALPATH: c_int = 2;
178
179pub const LIBSSH2_SFTP_RENAME_OVERWRITE: c_long = 0x1;
180pub const LIBSSH2_SFTP_RENAME_ATOMIC: c_long = 0x2;
181pub const LIBSSH2_SFTP_RENAME_NATIVE: c_long = 0x4;
182
183pub const LIBSSH2_INIT_NO_CRYPTO: c_int = 0x1;
184
185pub const LIBSSH2_SFTP_S_IFMT: c_ulong = 0o170000;
186pub const LIBSSH2_SFTP_S_IFIFO: c_ulong = 0o010000;
187pub const LIBSSH2_SFTP_S_IFCHR: c_ulong = 0o020000;
188pub const LIBSSH2_SFTP_S_IFDIR: c_ulong = 0o040000;
189pub const LIBSSH2_SFTP_S_IFBLK: c_ulong = 0o060000;
190pub const LIBSSH2_SFTP_S_IFREG: c_ulong = 0o100000;
191pub const LIBSSH2_SFTP_S_IFLNK: c_ulong = 0o120000;
192pub const LIBSSH2_SFTP_S_IFSOCK: c_ulong = 0o140000;
193
194pub const LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL: c_int = 0;
195pub const LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE: c_int = 1;
196pub const LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE: c_int = 2;
197
198pub const LIBSSH2_SESSION_BLOCK_INBOUND: c_int = 1;
199pub const LIBSSH2_SESSION_BLOCK_OUTBOUND: c_int = 2;
200
201pub const  LIBSSH2_TRACE_TRANS : c_int = 1<<1;
202pub const  LIBSSH2_TRACE_KEX   : c_int = 1<<2;
203pub const  LIBSSH2_TRACE_AUTH  : c_int = 1<<3;
204pub const  LIBSSH2_TRACE_CONN  : c_int = 1<<4;
205pub const  LIBSSH2_TRACE_SCP   : c_int = 1<<5;
206pub const  LIBSSH2_TRACE_SFTP  : c_int = 1<<6;
207pub const  LIBSSH2_TRACE_ERROR : c_int = 1<<7;
208pub const  LIBSSH2_TRACE_PUBLICKEY : c_int = 1<<8;
209pub const  LIBSSH2_TRACE_SOCKET : c_int = 1<<9;
210pub enum LIBSSH2_SESSION {}
211pub enum LIBSSH2_AGENT {}
212pub enum LIBSSH2_CHANNEL {}
213pub enum LIBSSH2_LISTENER {}
214pub enum LIBSSH2_KNOWNHOSTS {}
215pub enum LIBSSH2_SFTP {}
216pub enum LIBSSH2_SFTP_HANDLE {}
217
218pub type libssh2_int64_t = i64;
219pub type libssh2_uint64_t = u64;
220
221// libssh2_struct_stat is a typedef for libc::stat on all platforms, however,
222// Windows has a bunch of legacy around struct stat that makes things more
223// complicated to validate with systest.
224// The most reasonable looking solution to this is a newtype that derefs
225// to libc::stat.
226// We cannot use `pub struct libssh2_struct_stat(pub libc::stat)` because
227// that triggers a `no tuple structs in FFI` error.
228#[repr(C)]
229pub struct libssh2_struct_stat(libc::stat);
230
231impl std::ops::Deref for libssh2_struct_stat {
232    type Target = libc::stat;
233
234    fn deref(&self) -> &Self::Target {
235        &self.0
236    }
237}
238
239#[repr(C)]
240pub struct libssh2_agent_publickey {
241    pub magic: c_uint,
242    pub node: *mut c_void,
243    pub blob: *mut c_uchar,
244    pub blob_len: size_t,
245    pub comment: *mut c_char,
246}
247
248#[repr(C)]
249pub struct libssh2_knownhost {
250    pub magic: c_uint,
251    pub node: *mut c_void,
252    pub name: *mut c_char,
253    pub key: *mut c_char,
254    pub typemask: c_int,
255}
256
257#[repr(C)]
258#[derive(Copy, Clone)]
259pub struct LIBSSH2_SFTP_ATTRIBUTES {
260    pub flags: c_ulong,
261    pub filesize: libssh2_uint64_t,
262    pub uid: c_ulong,
263    pub gid: c_ulong,
264    pub permissions: c_ulong,
265    pub atime: c_ulong,
266    pub mtime: c_ulong,
267}
268
269#[repr(C)]
270#[derive(Copy, Clone)]
271pub struct LIBSSH2_SFTP_STATVFS {
272    pub f_bsize: libssh2_uint64_t,
273    pub f_frsize: libssh2_uint64_t,
274    pub f_blocks: libssh2_uint64_t,
275    pub f_bfree: libssh2_uint64_t,
276    pub f_bavail: libssh2_uint64_t,
277    pub f_files: libssh2_uint64_t,
278    pub f_ffree: libssh2_uint64_t,
279    pub f_favail: libssh2_uint64_t,
280    pub f_fsid: libssh2_uint64_t,
281    pub f_flag: libssh2_uint64_t,
282    pub f_namemax: libssh2_uint64_t,
283}
284
285pub type LIBSSH2_ALLOC_FUNC = extern "C" fn(size_t, *mut *mut c_void) -> *mut c_void;
286pub type LIBSSH2_FREE_FUNC = extern "C" fn(*mut c_void, *mut *mut c_void);
287pub type LIBSSH2_REALLOC_FUNC = extern "C" fn(*mut c_void, size_t, *mut *mut c_void) -> *mut c_void;
288pub type LIBSSH2_PASSWD_CHANGEREQ_FUNC = extern "C" fn(
289    sess: *mut LIBSSH2_SESSION,
290    newpw: *mut *mut c_char,
291    newpw_len: *mut c_int,
292    abstrakt: *mut *mut c_void,
293);
294
295pub type LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC = extern "C" fn(
296    username: *const c_char,
297    username_len: c_int,
298    instruction: *const c_char,
299    instruction_len: c_int,
300    num_prompts: c_int,
301    prompts: *const LIBSSH2_USERAUTH_KBDINT_PROMPT,
302    responses: *mut LIBSSH2_USERAUTH_KBDINT_RESPONSE,
303    abstrakt: *mut *mut c_void,
304);
305
306#[repr(C)]
307pub struct LIBSSH2_USERAUTH_KBDINT_PROMPT {
308    pub text: *mut c_uchar,
309    pub length: size_t,
310    pub echo: c_uchar,
311}
312
313#[repr(C)]
314pub struct LIBSSH2_USERAUTH_KBDINT_RESPONSE {
315    pub text: *mut c_char,
316    pub length: c_uint,
317}
318
319#[cfg(unix)]
320pub type libssh2_socket_t = c_int;
321#[cfg(all(windows, target_pointer_width = "32"))]
322pub type libssh2_socket_t = u32;
323#[cfg(all(windows, target_pointer_width = "64"))]
324pub type libssh2_socket_t = u64;
325
326extern "C" {
327    // misc
328    pub fn libssh2_init(flag: c_int) -> c_int;
329    pub fn libssh2_exit();
330    pub fn libssh2_free(sess: *mut LIBSSH2_SESSION, ptr: *mut c_void);
331    pub fn libssh2_hostkey_hash(session: *mut LIBSSH2_SESSION, hash_type: c_int) -> *const c_char;
332    pub fn libssh2_trace(session: *mut LIBSSH2_SESSION, bitmask: c_int) -> c_int;
333
334    // session
335    pub fn libssh2_session_init_ex(
336        alloc: Option<LIBSSH2_ALLOC_FUNC>,
337        free: Option<LIBSSH2_FREE_FUNC>,
338        realloc: Option<LIBSSH2_REALLOC_FUNC>,
339        abstrakt: *mut c_void,
340    ) -> *mut LIBSSH2_SESSION;
341    pub fn libssh2_session_abstract(session: *mut LIBSSH2_SESSION) -> *mut *mut c_void;
342    pub fn libssh2_session_free(sess: *mut LIBSSH2_SESSION) -> c_int;
343    pub fn libssh2_session_banner_get(sess: *mut LIBSSH2_SESSION) -> *const c_char;
344    pub fn libssh2_session_banner_set(sess: *mut LIBSSH2_SESSION, banner: *const c_char) -> c_int;
345    pub fn libssh2_session_disconnect_ex(
346        sess: *mut LIBSSH2_SESSION,
347        reason: c_int,
348        description: *const c_char,
349        lang: *const c_char,
350    ) -> c_int;
351    pub fn libssh2_session_flag(sess: *mut LIBSSH2_SESSION, flag: c_int, value: c_int) -> c_int;
352    pub fn libssh2_session_get_blocking(session: *mut LIBSSH2_SESSION) -> c_int;
353    pub fn libssh2_session_get_timeout(sess: *mut LIBSSH2_SESSION) -> c_long;
354    pub fn libssh2_session_hostkey(
355        sess: *mut LIBSSH2_SESSION,
356        len: *mut size_t,
357        kind: *mut c_int,
358    ) -> *const c_char;
359    pub fn libssh2_session_method_pref(
360        sess: *mut LIBSSH2_SESSION,
361        method_type: c_int,
362        prefs: *const c_char,
363    ) -> c_int;
364    pub fn libssh2_session_methods(sess: *mut LIBSSH2_SESSION, method_type: c_int)
365        -> *const c_char;
366    pub fn libssh2_session_set_blocking(session: *mut LIBSSH2_SESSION, blocking: c_int);
367    pub fn libssh2_session_set_timeout(session: *mut LIBSSH2_SESSION, timeout: c_long);
368    pub fn libssh2_session_supported_algs(
369        session: *mut LIBSSH2_SESSION,
370        method_type: c_int,
371        algs: *mut *mut *const c_char,
372    ) -> c_int;
373    pub fn libssh2_session_last_errno(sess: *mut LIBSSH2_SESSION) -> c_int;
374    pub fn libssh2_session_last_error(
375        sess: *mut LIBSSH2_SESSION,
376        msg: *mut *mut c_char,
377        len: *mut c_int,
378        want_buf: c_int,
379    ) -> c_int;
380    pub fn libssh2_session_handshake(sess: *mut LIBSSH2_SESSION, socket: libssh2_socket_t)
381        -> c_int;
382    pub fn libssh2_keepalive_config(
383        sess: *mut LIBSSH2_SESSION,
384        want_reply: c_int,
385        interval: c_uint,
386    );
387    pub fn libssh2_keepalive_send(sess: *mut LIBSSH2_SESSION, seconds_to_next: *mut c_int)
388        -> c_int;
389    pub fn libssh2_session_block_directions(sess: *mut LIBSSH2_SESSION) -> c_int;
390
391    // agent
392    pub fn libssh2_agent_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_AGENT;
393    pub fn libssh2_agent_free(agent: *mut LIBSSH2_AGENT);
394    pub fn libssh2_agent_connect(agent: *mut LIBSSH2_AGENT) -> c_int;
395    pub fn libssh2_agent_disconnect(agent: *mut LIBSSH2_AGENT) -> c_int;
396    pub fn libssh2_agent_list_identities(agent: *mut LIBSSH2_AGENT) -> c_int;
397    pub fn libssh2_agent_get_identity(
398        agent: *mut LIBSSH2_AGENT,
399        store: *mut *mut libssh2_agent_publickey,
400        prev: *mut libssh2_agent_publickey,
401    ) -> c_int;
402    pub fn libssh2_agent_userauth(
403        agent: *mut LIBSSH2_AGENT,
404        username: *const c_char,
405        identity: *mut libssh2_agent_publickey,
406    ) -> c_int;
407
408    // channels
409    pub fn libssh2_channel_free(chan: *mut LIBSSH2_CHANNEL) -> c_int;
410    pub fn libssh2_channel_close(chan: *mut LIBSSH2_CHANNEL) -> c_int;
411    pub fn libssh2_channel_wait_closed(chan: *mut LIBSSH2_CHANNEL) -> c_int;
412    pub fn libssh2_channel_wait_eof(chan: *mut LIBSSH2_CHANNEL) -> c_int;
413    pub fn libssh2_channel_eof(chan: *mut LIBSSH2_CHANNEL) -> c_int;
414    pub fn libssh2_channel_process_startup(
415        chan: *mut LIBSSH2_CHANNEL,
416        req: *const c_char,
417        req_len: c_uint,
418        msg: *const c_char,
419        msg_len: c_uint,
420    ) -> c_int;
421    pub fn libssh2_channel_flush_ex(chan: *mut LIBSSH2_CHANNEL, streamid: c_int) -> c_int;
422    pub fn libssh2_channel_write_ex(
423        chan: *mut LIBSSH2_CHANNEL,
424        stream_id: c_int,
425        buf: *const c_char,
426        buflen: size_t,
427    ) -> ssize_t;
428    pub fn libssh2_channel_get_exit_signal(
429        chan: *mut LIBSSH2_CHANNEL,
430        exitsignal: *mut *mut c_char,
431        exitsignal_len: *mut size_t,
432        errmsg: *mut *mut c_char,
433        errmsg_len: *mut size_t,
434        langtag: *mut *mut c_char,
435        langtag_len: *mut size_t,
436    ) -> c_int;
437    pub fn libssh2_channel_get_exit_status(chan: *mut LIBSSH2_CHANNEL) -> c_int;
438    pub fn libssh2_channel_open_ex(
439        sess: *mut LIBSSH2_SESSION,
440        channel_type: *const c_char,
441        channel_type_len: c_uint,
442        window_size: c_uint,
443        packet_size: c_uint,
444        message: *const c_char,
445        message_len: c_uint,
446    ) -> *mut LIBSSH2_CHANNEL;
447    pub fn libssh2_channel_read_ex(
448        chan: *mut LIBSSH2_CHANNEL,
449        stream_id: c_int,
450        buf: *mut c_char,
451        buflen: size_t,
452    ) -> ssize_t;
453    pub fn libssh2_channel_setenv_ex(
454        chan: *mut LIBSSH2_CHANNEL,
455        var: *const c_char,
456        varlen: c_uint,
457        val: *const c_char,
458        vallen: c_uint,
459    ) -> c_int;
460    pub fn libssh2_channel_send_eof(chan: *mut LIBSSH2_CHANNEL) -> c_int;
461    pub fn libssh2_channel_request_pty_ex(
462        chan: *mut LIBSSH2_CHANNEL,
463        term: *const c_char,
464        termlen: c_uint,
465        modes: *const c_char,
466        modeslen: c_uint,
467        width: c_int,
468        height: c_int,
469        width_px: c_int,
470        height_px: c_int,
471    ) -> c_int;
472    pub fn libssh2_channel_request_pty_size_ex(
473        chan: *mut LIBSSH2_CHANNEL,
474        width: c_int,
475        height: c_int,
476        width_px: c_int,
477        height_px: c_int,
478    ) -> c_int;
479    pub fn libssh2_channel_window_read_ex(
480        chan: *mut LIBSSH2_CHANNEL,
481        read_avail: *mut c_ulong,
482        window_size_initial: *mut c_ulong,
483    ) -> c_ulong;
484    pub fn libssh2_channel_window_write_ex(
485        chan: *mut LIBSSH2_CHANNEL,
486        window_size_initial: *mut c_ulong,
487    ) -> c_ulong;
488    pub fn libssh2_channel_receive_window_adjust2(
489        chan: *mut LIBSSH2_CHANNEL,
490        adjust: c_ulong,
491        force: c_uchar,
492        window: *mut c_uint,
493    ) -> c_int;
494    pub fn libssh2_channel_direct_tcpip_ex(
495        ses: *mut LIBSSH2_SESSION,
496        host: *const c_char,
497        port: c_int,
498        shost: *const c_char,
499        sport: c_int,
500    ) -> *mut LIBSSH2_CHANNEL;
501    pub fn libssh2_channel_direct_streamlocal_ex(
502        ses: *mut LIBSSH2_SESSION,
503        socket_path: *const c_char,
504        shost: *const c_char,
505        sport: c_int,
506    ) -> *mut LIBSSH2_CHANNEL;
507    pub fn libssh2_channel_forward_accept(listener: *mut LIBSSH2_LISTENER) -> *mut LIBSSH2_CHANNEL;
508    pub fn libssh2_channel_forward_cancel(listener: *mut LIBSSH2_LISTENER) -> c_int;
509    pub fn libssh2_channel_forward_listen_ex(
510        sess: *mut LIBSSH2_SESSION,
511        host: *const c_char,
512        port: c_int,
513        bound_port: *mut c_int,
514        queue_maxsize: c_int,
515    ) -> *mut LIBSSH2_LISTENER;
516    pub fn libssh2_channel_handle_extended_data2(
517        channel: *mut LIBSSH2_CHANNEL,
518        mode: c_int,
519    ) -> c_int;
520    pub fn libssh2_channel_request_auth_agent(channel: *mut LIBSSH2_CHANNEL) -> c_int;
521
522    // userauth
523    pub fn libssh2_userauth_banner(sess: *mut LIBSSH2_SESSION, banner: *mut *mut c_char) -> c_int;
524    pub fn libssh2_userauth_authenticated(sess: *mut LIBSSH2_SESSION) -> c_int;
525    pub fn libssh2_userauth_list(
526        sess: *mut LIBSSH2_SESSION,
527        username: *const c_char,
528        username_len: c_uint,
529    ) -> *mut c_char;
530    pub fn libssh2_userauth_hostbased_fromfile_ex(
531        sess: *mut LIBSSH2_SESSION,
532        username: *const c_char,
533        username_len: c_uint,
534        publickey: *const c_char,
535        privatekey: *const c_char,
536        passphrase: *const c_char,
537        hostname: *const c_char,
538        hostname_len: c_uint,
539        local_username: *const c_char,
540        local_len: c_uint,
541    ) -> c_int;
542    pub fn libssh2_userauth_publickey_fromfile_ex(
543        sess: *mut LIBSSH2_SESSION,
544        username: *const c_char,
545        username_len: c_uint,
546        publickey: *const c_char,
547        privatekey: *const c_char,
548        passphrase: *const c_char,
549    ) -> c_int;
550    pub fn libssh2_userauth_publickey_frommemory(
551        sess: *mut LIBSSH2_SESSION,
552        username: *const c_char,
553        username_len: size_t,
554        publickeydata: *const c_char,
555        publickeydata_len: size_t,
556        privatekeydata: *const c_char,
557        privatekeydata_len: size_t,
558        passphrase: *const c_char,
559    ) -> c_int;
560    pub fn libssh2_userauth_password_ex(
561        session: *mut LIBSSH2_SESSION,
562        username: *const c_char,
563        username_len: c_uint,
564        password: *const c_char,
565        password_len: c_uint,
566        password_change_cb: Option<LIBSSH2_PASSWD_CHANGEREQ_FUNC>,
567    ) -> c_int;
568    pub fn libssh2_userauth_keyboard_interactive_ex(
569        session: *mut LIBSSH2_SESSION,
570        username: *const c_char,
571        username_len: c_uint,
572        callback: Option<LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC>,
573    ) -> c_int;
574
575    // knownhost
576    pub fn libssh2_knownhost_free(hosts: *mut LIBSSH2_KNOWNHOSTS);
577    pub fn libssh2_knownhost_addc(
578        hosts: *mut LIBSSH2_KNOWNHOSTS,
579        host: *const c_char,
580        salt: *const c_char,
581        key: *const c_char,
582        keylen: size_t,
583        comment: *const c_char,
584        commentlen: size_t,
585        typemask: c_int,
586        store: *mut *mut libssh2_knownhost,
587    ) -> c_int;
588    pub fn libssh2_knownhost_check(
589        hosts: *mut LIBSSH2_KNOWNHOSTS,
590        host: *const c_char,
591        key: *const c_char,
592        keylen: size_t,
593        typemask: c_int,
594        knownhost: *mut *mut libssh2_knownhost,
595    ) -> c_int;
596    pub fn libssh2_knownhost_checkp(
597        hosts: *mut LIBSSH2_KNOWNHOSTS,
598        host: *const c_char,
599        port: c_int,
600        key: *const c_char,
601        keylen: size_t,
602        typemask: c_int,
603        knownhost: *mut *mut libssh2_knownhost,
604    ) -> c_int;
605    pub fn libssh2_knownhost_del(
606        hosts: *mut LIBSSH2_KNOWNHOSTS,
607        entry: *mut libssh2_knownhost,
608    ) -> c_int;
609    pub fn libssh2_knownhost_get(
610        hosts: *mut LIBSSH2_KNOWNHOSTS,
611        store: *mut *mut libssh2_knownhost,
612        prev: *mut libssh2_knownhost,
613    ) -> c_int;
614    pub fn libssh2_knownhost_readfile(
615        hosts: *mut LIBSSH2_KNOWNHOSTS,
616        filename: *const c_char,
617        kind: c_int,
618    ) -> c_int;
619    pub fn libssh2_knownhost_readline(
620        hosts: *mut LIBSSH2_KNOWNHOSTS,
621        line: *const c_char,
622        len: size_t,
623        kind: c_int,
624    ) -> c_int;
625    pub fn libssh2_knownhost_writefile(
626        hosts: *mut LIBSSH2_KNOWNHOSTS,
627        filename: *const c_char,
628        kind: c_int,
629    ) -> c_int;
630    pub fn libssh2_knownhost_writeline(
631        hosts: *mut LIBSSH2_KNOWNHOSTS,
632        known: *mut libssh2_knownhost,
633        buffer: *mut c_char,
634        buflen: size_t,
635        outlen: *mut size_t,
636        kind: c_int,
637    ) -> c_int;
638    pub fn libssh2_knownhost_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_KNOWNHOSTS;
639
640    // scp
641    #[deprecated(note = "dangerously unsafe on windows, use libssh2_scp_recv2 instead")]
642    pub fn libssh2_scp_recv(
643        sess: *mut LIBSSH2_SESSION,
644        path: *const c_char,
645        sb: *mut libc::stat,
646    ) -> *mut LIBSSH2_CHANNEL;
647
648    pub fn libssh2_scp_recv2(
649        sess: *mut LIBSSH2_SESSION,
650        path: *const c_char,
651        sb: *mut libssh2_struct_stat,
652    ) -> *mut LIBSSH2_CHANNEL;
653
654    pub fn libssh2_scp_send64(
655        sess: *mut LIBSSH2_SESSION,
656        path: *const c_char,
657        mode: c_int,
658        size: libssh2_int64_t,
659        mtime: libc::time_t,
660        atime: libc::time_t,
661    ) -> *mut LIBSSH2_CHANNEL;
662
663    // sftp
664    pub fn libssh2_sftp_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_SFTP;
665    pub fn libssh2_sftp_shutdown(sftp: *mut LIBSSH2_SFTP) -> c_int;
666    pub fn libssh2_sftp_last_error(sftp: *mut LIBSSH2_SFTP) -> c_ulong;
667    pub fn libssh2_sftp_open_ex(
668        sftp: *mut LIBSSH2_SFTP,
669        filename: *const c_char,
670        filename_len: c_uint,
671        flags: c_ulong,
672        mode: c_long,
673        open_type: c_int,
674    ) -> *mut LIBSSH2_SFTP_HANDLE;
675    pub fn libssh2_sftp_close_handle(handle: *mut LIBSSH2_SFTP_HANDLE) -> c_int;
676    pub fn libssh2_sftp_mkdir_ex(
677        sftp: *mut LIBSSH2_SFTP,
678        path: *const c_char,
679        path_len: c_uint,
680        mode: c_long,
681    ) -> c_int;
682    pub fn libssh2_sftp_fsync(handle: *mut LIBSSH2_SFTP_HANDLE) -> c_int;
683    pub fn libssh2_sftp_fstat_ex(
684        handle: *mut LIBSSH2_SFTP_HANDLE,
685        attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
686        setstat: c_int,
687    ) -> c_int;
688    pub fn libssh2_sftp_fstatvfs(
689        handle: *mut LIBSSH2_SFTP_HANDLE,
690        attrs: *mut LIBSSH2_SFTP_STATVFS,
691    ) -> c_int;
692    pub fn libssh2_sftp_stat_ex(
693        sftp: *mut LIBSSH2_SFTP,
694        path: *const c_char,
695        path_len: c_uint,
696        stat_type: c_int,
697        attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
698    ) -> c_int;
699    pub fn libssh2_sftp_read(
700        handle: *mut LIBSSH2_SFTP_HANDLE,
701        buf: *mut c_char,
702        len: size_t,
703    ) -> ssize_t;
704    pub fn libssh2_sftp_symlink_ex(
705        sftp: *mut LIBSSH2_SFTP,
706        path: *const c_char,
707        path_len: c_uint,
708        target: *mut c_char,
709        target_len: c_uint,
710        link_type: c_int,
711    ) -> c_int;
712    pub fn libssh2_sftp_rename_ex(
713        sftp: *mut LIBSSH2_SFTP,
714        src: *const c_char,
715        src_len: c_uint,
716        dst: *const c_char,
717        dst_len: c_uint,
718        flags: c_long,
719    ) -> c_int;
720    pub fn libssh2_sftp_rmdir_ex(
721        sftp: *mut LIBSSH2_SFTP,
722        path: *const c_char,
723        path_len: c_uint,
724    ) -> c_int;
725    pub fn libssh2_sftp_write(
726        handle: *mut LIBSSH2_SFTP_HANDLE,
727        buffer: *const c_char,
728        len: size_t,
729    ) -> ssize_t;
730    pub fn libssh2_sftp_tell64(handle: *mut LIBSSH2_SFTP_HANDLE) -> libssh2_uint64_t;
731    pub fn libssh2_sftp_seek64(handle: *mut LIBSSH2_SFTP_HANDLE, off: libssh2_uint64_t);
732    pub fn libssh2_sftp_readdir_ex(
733        handle: *mut LIBSSH2_SFTP_HANDLE,
734        buffer: *mut c_char,
735        buffer_len: size_t,
736        longentry: *mut c_char,
737        longentry_len: size_t,
738        attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
739    ) -> c_int;
740    pub fn libssh2_sftp_unlink_ex(
741        sftp: *mut LIBSSH2_SFTP,
742        filename: *const c_char,
743        filename_len: c_uint,
744    ) -> c_int;
745}
746
747#[test]
748fn smoke() {
749    unsafe { libssh2_init(0) };
750}
751
752#[doc(hidden)]
753pub fn issue_14344_workaround() {}
754
755pub fn init() {
756    use std::sync::Once;
757
758    static INIT: Once = Once::new();
759    INIT.call_once(|| unsafe {
760        platform_init();
761        assert_eq!(libc::atexit(shutdown), 0);
762    });
763    extern "C" fn shutdown() {
764        unsafe {
765            libssh2_exit();
766        }
767    }
768
769    #[cfg(unix)]
770    unsafe fn platform_init() {
771        // On Unix we want to funnel through openssl_sys to initialize OpenSSL,
772        // so be sure to tell libssh2 to not do its own thing as we've already
773        // taken care of it.
774        openssl_sys::init();
775        assert_eq!(libssh2_init(LIBSSH2_INIT_NO_CRYPTO), 0);
776    }
777
778    #[cfg(windows)]
779    unsafe fn platform_init() {
780        // On Windows we want to be sure to tell libssh2 to initialize
781        // everything, as we're not managing crypto elsewhere ourselves. Also to
782        // fix alexcrichton/git2-rs#202
783        assert_eq!(libssh2_init(0), 0);
784    }
785}