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#[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 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 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 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 pub fn libssh2_agent_set_identity_path(agent: *mut LIBSSH2_AGENT, path: *const c_char);
408 pub fn libssh2_agent_get_identity_path(agent: *mut LIBSSH2_AGENT) -> *const c_char;
409
410 pub fn libssh2_channel_free(chan: *mut LIBSSH2_CHANNEL) -> c_int;
412 pub fn libssh2_channel_close(chan: *mut LIBSSH2_CHANNEL) -> c_int;
413 pub fn libssh2_channel_wait_closed(chan: *mut LIBSSH2_CHANNEL) -> c_int;
414 pub fn libssh2_channel_wait_eof(chan: *mut LIBSSH2_CHANNEL) -> c_int;
415 pub fn libssh2_channel_eof(chan: *mut LIBSSH2_CHANNEL) -> c_int;
416 pub fn libssh2_channel_process_startup(
417 chan: *mut LIBSSH2_CHANNEL,
418 req: *const c_char,
419 req_len: c_uint,
420 msg: *const c_char,
421 msg_len: c_uint,
422 ) -> c_int;
423 pub fn libssh2_channel_flush_ex(chan: *mut LIBSSH2_CHANNEL, streamid: c_int) -> c_int;
424 pub fn libssh2_channel_write_ex(
425 chan: *mut LIBSSH2_CHANNEL,
426 stream_id: c_int,
427 buf: *const c_char,
428 buflen: size_t,
429 ) -> ssize_t;
430 pub fn libssh2_channel_get_exit_signal(
431 chan: *mut LIBSSH2_CHANNEL,
432 exitsignal: *mut *mut c_char,
433 exitsignal_len: *mut size_t,
434 errmsg: *mut *mut c_char,
435 errmsg_len: *mut size_t,
436 langtag: *mut *mut c_char,
437 langtag_len: *mut size_t,
438 ) -> c_int;
439 pub fn libssh2_channel_get_exit_status(chan: *mut LIBSSH2_CHANNEL) -> c_int;
440 pub fn libssh2_channel_open_ex(
441 sess: *mut LIBSSH2_SESSION,
442 channel_type: *const c_char,
443 channel_type_len: c_uint,
444 window_size: c_uint,
445 packet_size: c_uint,
446 message: *const c_char,
447 message_len: c_uint,
448 ) -> *mut LIBSSH2_CHANNEL;
449 pub fn libssh2_channel_read_ex(
450 chan: *mut LIBSSH2_CHANNEL,
451 stream_id: c_int,
452 buf: *mut c_char,
453 buflen: size_t,
454 ) -> ssize_t;
455 pub fn libssh2_channel_setenv_ex(
456 chan: *mut LIBSSH2_CHANNEL,
457 var: *const c_char,
458 varlen: c_uint,
459 val: *const c_char,
460 vallen: c_uint,
461 ) -> c_int;
462 pub fn libssh2_channel_send_eof(chan: *mut LIBSSH2_CHANNEL) -> c_int;
463 pub fn libssh2_channel_request_pty_ex(
464 chan: *mut LIBSSH2_CHANNEL,
465 term: *const c_char,
466 termlen: c_uint,
467 modes: *const c_char,
468 modeslen: c_uint,
469 width: c_int,
470 height: c_int,
471 width_px: c_int,
472 height_px: c_int,
473 ) -> c_int;
474 pub fn libssh2_channel_request_pty_size_ex(
475 chan: *mut LIBSSH2_CHANNEL,
476 width: c_int,
477 height: c_int,
478 width_px: c_int,
479 height_px: c_int,
480 ) -> c_int;
481 pub fn libssh2_channel_window_read_ex(
482 chan: *mut LIBSSH2_CHANNEL,
483 read_avail: *mut c_ulong,
484 window_size_initial: *mut c_ulong,
485 ) -> c_ulong;
486 pub fn libssh2_channel_window_write_ex(
487 chan: *mut LIBSSH2_CHANNEL,
488 window_size_initial: *mut c_ulong,
489 ) -> c_ulong;
490 pub fn libssh2_channel_receive_window_adjust2(
491 chan: *mut LIBSSH2_CHANNEL,
492 adjust: c_ulong,
493 force: c_uchar,
494 window: *mut c_uint,
495 ) -> c_int;
496 pub fn libssh2_channel_direct_tcpip_ex(
497 ses: *mut LIBSSH2_SESSION,
498 host: *const c_char,
499 port: c_int,
500 shost: *const c_char,
501 sport: c_int,
502 ) -> *mut LIBSSH2_CHANNEL;
503 pub fn libssh2_channel_direct_streamlocal_ex(
504 ses: *mut LIBSSH2_SESSION,
505 socket_path: *const c_char,
506 shost: *const c_char,
507 sport: c_int,
508 ) -> *mut LIBSSH2_CHANNEL;
509 pub fn libssh2_channel_forward_accept(listener: *mut LIBSSH2_LISTENER) -> *mut LIBSSH2_CHANNEL;
510 pub fn libssh2_channel_forward_cancel(listener: *mut LIBSSH2_LISTENER) -> c_int;
511 pub fn libssh2_channel_forward_listen_ex(
512 sess: *mut LIBSSH2_SESSION,
513 host: *const c_char,
514 port: c_int,
515 bound_port: *mut c_int,
516 queue_maxsize: c_int,
517 ) -> *mut LIBSSH2_LISTENER;
518 pub fn libssh2_channel_handle_extended_data2(
519 channel: *mut LIBSSH2_CHANNEL,
520 mode: c_int,
521 ) -> c_int;
522 pub fn libssh2_channel_request_auth_agent(channel: *mut LIBSSH2_CHANNEL) -> c_int;
523
524 pub fn libssh2_userauth_banner(sess: *mut LIBSSH2_SESSION, banner: *mut *mut c_char) -> c_int;
526 pub fn libssh2_userauth_authenticated(sess: *mut LIBSSH2_SESSION) -> c_int;
527 pub fn libssh2_userauth_list(
528 sess: *mut LIBSSH2_SESSION,
529 username: *const c_char,
530 username_len: c_uint,
531 ) -> *mut c_char;
532 pub fn libssh2_userauth_hostbased_fromfile_ex(
533 sess: *mut LIBSSH2_SESSION,
534 username: *const c_char,
535 username_len: c_uint,
536 publickey: *const c_char,
537 privatekey: *const c_char,
538 passphrase: *const c_char,
539 hostname: *const c_char,
540 hostname_len: c_uint,
541 local_username: *const c_char,
542 local_len: c_uint,
543 ) -> c_int;
544 pub fn libssh2_userauth_publickey_fromfile_ex(
545 sess: *mut LIBSSH2_SESSION,
546 username: *const c_char,
547 username_len: c_uint,
548 publickey: *const c_char,
549 privatekey: *const c_char,
550 passphrase: *const c_char,
551 ) -> c_int;
552 pub fn libssh2_userauth_publickey_frommemory(
553 sess: *mut LIBSSH2_SESSION,
554 username: *const c_char,
555 username_len: size_t,
556 publickeydata: *const c_char,
557 publickeydata_len: size_t,
558 privatekeydata: *const c_char,
559 privatekeydata_len: size_t,
560 passphrase: *const c_char,
561 ) -> c_int;
562 pub fn libssh2_userauth_password_ex(
563 session: *mut LIBSSH2_SESSION,
564 username: *const c_char,
565 username_len: c_uint,
566 password: *const c_char,
567 password_len: c_uint,
568 password_change_cb: Option<LIBSSH2_PASSWD_CHANGEREQ_FUNC>,
569 ) -> c_int;
570 pub fn libssh2_userauth_keyboard_interactive_ex(
571 session: *mut LIBSSH2_SESSION,
572 username: *const c_char,
573 username_len: c_uint,
574 callback: Option<LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC>,
575 ) -> c_int;
576
577 pub fn libssh2_knownhost_free(hosts: *mut LIBSSH2_KNOWNHOSTS);
579 pub fn libssh2_knownhost_addc(
580 hosts: *mut LIBSSH2_KNOWNHOSTS,
581 host: *const c_char,
582 salt: *const c_char,
583 key: *const c_char,
584 keylen: size_t,
585 comment: *const c_char,
586 commentlen: size_t,
587 typemask: c_int,
588 store: *mut *mut libssh2_knownhost,
589 ) -> c_int;
590 pub fn libssh2_knownhost_check(
591 hosts: *mut LIBSSH2_KNOWNHOSTS,
592 host: *const c_char,
593 key: *const c_char,
594 keylen: size_t,
595 typemask: c_int,
596 knownhost: *mut *mut libssh2_knownhost,
597 ) -> c_int;
598 pub fn libssh2_knownhost_checkp(
599 hosts: *mut LIBSSH2_KNOWNHOSTS,
600 host: *const c_char,
601 port: c_int,
602 key: *const c_char,
603 keylen: size_t,
604 typemask: c_int,
605 knownhost: *mut *mut libssh2_knownhost,
606 ) -> c_int;
607 pub fn libssh2_knownhost_del(
608 hosts: *mut LIBSSH2_KNOWNHOSTS,
609 entry: *mut libssh2_knownhost,
610 ) -> c_int;
611 pub fn libssh2_knownhost_get(
612 hosts: *mut LIBSSH2_KNOWNHOSTS,
613 store: *mut *mut libssh2_knownhost,
614 prev: *mut libssh2_knownhost,
615 ) -> c_int;
616 pub fn libssh2_knownhost_readfile(
617 hosts: *mut LIBSSH2_KNOWNHOSTS,
618 filename: *const c_char,
619 kind: c_int,
620 ) -> c_int;
621 pub fn libssh2_knownhost_readline(
622 hosts: *mut LIBSSH2_KNOWNHOSTS,
623 line: *const c_char,
624 len: size_t,
625 kind: c_int,
626 ) -> c_int;
627 pub fn libssh2_knownhost_writefile(
628 hosts: *mut LIBSSH2_KNOWNHOSTS,
629 filename: *const c_char,
630 kind: c_int,
631 ) -> c_int;
632 pub fn libssh2_knownhost_writeline(
633 hosts: *mut LIBSSH2_KNOWNHOSTS,
634 known: *mut libssh2_knownhost,
635 buffer: *mut c_char,
636 buflen: size_t,
637 outlen: *mut size_t,
638 kind: c_int,
639 ) -> c_int;
640 pub fn libssh2_knownhost_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_KNOWNHOSTS;
641
642 #[deprecated(note = "dangerously unsafe on windows, use libssh2_scp_recv2 instead")]
644 pub fn libssh2_scp_recv(
645 sess: *mut LIBSSH2_SESSION,
646 path: *const c_char,
647 sb: *mut libc::stat,
648 ) -> *mut LIBSSH2_CHANNEL;
649
650 pub fn libssh2_scp_recv2(
651 sess: *mut LIBSSH2_SESSION,
652 path: *const c_char,
653 sb: *mut libssh2_struct_stat,
654 ) -> *mut LIBSSH2_CHANNEL;
655
656 pub fn libssh2_scp_send64(
657 sess: *mut LIBSSH2_SESSION,
658 path: *const c_char,
659 mode: c_int,
660 size: libssh2_int64_t,
661 mtime: libc::time_t,
662 atime: libc::time_t,
663 ) -> *mut LIBSSH2_CHANNEL;
664
665 pub fn libssh2_sftp_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_SFTP;
667 pub fn libssh2_sftp_shutdown(sftp: *mut LIBSSH2_SFTP) -> c_int;
668 pub fn libssh2_sftp_last_error(sftp: *mut LIBSSH2_SFTP) -> c_ulong;
669 pub fn libssh2_sftp_open_ex(
670 sftp: *mut LIBSSH2_SFTP,
671 filename: *const c_char,
672 filename_len: c_uint,
673 flags: c_ulong,
674 mode: c_long,
675 open_type: c_int,
676 ) -> *mut LIBSSH2_SFTP_HANDLE;
677 pub fn libssh2_sftp_close_handle(handle: *mut LIBSSH2_SFTP_HANDLE) -> c_int;
678 pub fn libssh2_sftp_mkdir_ex(
679 sftp: *mut LIBSSH2_SFTP,
680 path: *const c_char,
681 path_len: c_uint,
682 mode: c_long,
683 ) -> c_int;
684 pub fn libssh2_sftp_fsync(handle: *mut LIBSSH2_SFTP_HANDLE) -> c_int;
685 pub fn libssh2_sftp_fstat_ex(
686 handle: *mut LIBSSH2_SFTP_HANDLE,
687 attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
688 setstat: c_int,
689 ) -> c_int;
690 pub fn libssh2_sftp_fstatvfs(
691 handle: *mut LIBSSH2_SFTP_HANDLE,
692 attrs: *mut LIBSSH2_SFTP_STATVFS,
693 ) -> c_int;
694 pub fn libssh2_sftp_stat_ex(
695 sftp: *mut LIBSSH2_SFTP,
696 path: *const c_char,
697 path_len: c_uint,
698 stat_type: c_int,
699 attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
700 ) -> c_int;
701 pub fn libssh2_sftp_read(
702 handle: *mut LIBSSH2_SFTP_HANDLE,
703 buf: *mut c_char,
704 len: size_t,
705 ) -> ssize_t;
706 pub fn libssh2_sftp_symlink_ex(
707 sftp: *mut LIBSSH2_SFTP,
708 path: *const c_char,
709 path_len: c_uint,
710 target: *mut c_char,
711 target_len: c_uint,
712 link_type: c_int,
713 ) -> c_int;
714 pub fn libssh2_sftp_rename_ex(
715 sftp: *mut LIBSSH2_SFTP,
716 src: *const c_char,
717 src_len: c_uint,
718 dst: *const c_char,
719 dst_len: c_uint,
720 flags: c_long,
721 ) -> c_int;
722 pub fn libssh2_sftp_rmdir_ex(
723 sftp: *mut LIBSSH2_SFTP,
724 path: *const c_char,
725 path_len: c_uint,
726 ) -> c_int;
727 pub fn libssh2_sftp_write(
728 handle: *mut LIBSSH2_SFTP_HANDLE,
729 buffer: *const c_char,
730 len: size_t,
731 ) -> ssize_t;
732 pub fn libssh2_sftp_tell64(handle: *mut LIBSSH2_SFTP_HANDLE) -> libssh2_uint64_t;
733 pub fn libssh2_sftp_seek64(handle: *mut LIBSSH2_SFTP_HANDLE, off: libssh2_uint64_t);
734 pub fn libssh2_sftp_readdir_ex(
735 handle: *mut LIBSSH2_SFTP_HANDLE,
736 buffer: *mut c_char,
737 buffer_len: size_t,
738 longentry: *mut c_char,
739 longentry_len: size_t,
740 attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
741 ) -> c_int;
742 pub fn libssh2_sftp_unlink_ex(
743 sftp: *mut LIBSSH2_SFTP,
744 filename: *const c_char,
745 filename_len: c_uint,
746 ) -> c_int;
747}
748
749#[test]
750fn smoke() {
751 unsafe { libssh2_init(0) };
752}
753
754#[doc(hidden)]
755pub fn issue_14344_workaround() {}
756
757pub fn init() {
758 use std::sync::Once;
759
760 static INIT: Once = Once::new();
761 INIT.call_once(|| unsafe {
762 platform_init();
763 assert_eq!(libc::atexit(shutdown), 0);
764 });
765 extern "C" fn shutdown() {
766 unsafe {
767 libssh2_exit();
768 }
769 }
770
771 #[cfg(unix)]
772 unsafe fn platform_init() {
773 openssl_sys::init();
777 assert_eq!(libssh2_init(LIBSSH2_INIT_NO_CRYPTO), 0);
778 }
779
780 #[cfg(windows)]
781 unsafe fn platform_init() {
782 assert_eq!(libssh2_init(0), 0);
786 }
787}