]> git.proxmox.com Git - rustc.git/blob - vendor/libssh2-sys/lib.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / libssh2-sys / lib.rs
1 #![doc(html_root_url = "http://alexcrichton.com/ssh2-rs")]
2 #![allow(bad_style)]
3 #![allow(unused_extern_crates)]
4
5 extern crate libc;
6
7 extern crate libz_sys;
8 #[cfg(unix)]
9 extern crate openssl_sys;
10
11 use libc::ssize_t;
12 use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void, size_t};
13
14 pub const SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT: c_int = 1;
15 pub const SSH_DISCONNECT_PROTOCOL_ERROR: c_int = 2;
16 pub const SSH_DISCONNECT_KEY_EXCHANGE_FAILED: c_int = 3;
17 pub const SSH_DISCONNECT_RESERVED: c_int = 4;
18 pub const SSH_DISCONNECT_MAC_ERROR: c_int = 5;
19 pub const SSH_DISCONNECT_COMPRESSION_ERROR: c_int = 6;
20 pub const SSH_DISCONNECT_SERVICE_NOT_AVAILABLE: c_int = 7;
21 pub const SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED: c_int = 8;
22 pub const SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE: c_int = 9;
23 pub const SSH_DISCONNECT_CONNECTION_LOST: c_int = 10;
24 pub const SSH_DISCONNECT_BY_APPLICATION: c_int = 11;
25 pub const SSH_DISCONNECT_TOO_MANY_CONNECTIONS: c_int = 12;
26 pub const SSH_DISCONNECT_AUTH_CANCELLED_BY_USER: c_int = 13;
27 pub const SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE: c_int = 14;
28 pub const SSH_DISCONNECT_ILLEGAL_USER_NAME: c_int = 15;
29
30 pub const LIBSSH2_FLAG_SIGPIPE: c_int = 1;
31 pub const LIBSSH2_FLAG_COMPRESS: c_int = 2;
32
33 pub const LIBSSH2_HOSTKEY_TYPE_UNKNOWN: c_int = 0;
34 pub const LIBSSH2_HOSTKEY_TYPE_RSA: c_int = 1;
35 pub const LIBSSH2_HOSTKEY_TYPE_DSS: c_int = 2;
36 pub const LIBSSH2_HOSTKEY_TYPE_ECDSA_256: c_int = 3;
37 pub const LIBSSH2_HOSTKEY_TYPE_ECDSA_384: c_int = 4;
38 pub const LIBSSH2_HOSTKEY_TYPE_ECDSA_521: c_int = 5;
39 pub const LIBSSH2_HOSTKEY_TYPE_ED25519: c_int = 6;
40
41 pub const LIBSSH2_METHOD_KEX: c_int = 0;
42 pub const LIBSSH2_METHOD_HOSTKEY: c_int = 1;
43 pub const LIBSSH2_METHOD_CRYPT_CS: c_int = 2;
44 pub const LIBSSH2_METHOD_CRYPT_SC: c_int = 3;
45 pub const LIBSSH2_METHOD_MAC_CS: c_int = 4;
46 pub const LIBSSH2_METHOD_MAC_SC: c_int = 5;
47 pub const LIBSSH2_METHOD_COMP_CS: c_int = 6;
48 pub const LIBSSH2_METHOD_COMP_SC: c_int = 7;
49 pub const LIBSSH2_METHOD_LANG_CS: c_int = 8;
50 pub const LIBSSH2_METHOD_LANG_SC: c_int = 9;
51 pub const LIBSSH2_METHOD_SIGN_ALGO: c_int = 10;
52
53 pub const LIBSSH2_CHANNEL_PACKET_DEFAULT: c_uint = 32768;
54 pub const LIBSSH2_CHANNEL_WINDOW_DEFAULT: c_uint = 2 * 1024 * 1024;
55
56 pub const LIBSSH2_ERROR_BANNER_RECV: c_int = -2;
57 pub const LIBSSH2_ERROR_BANNER_SEND: c_int = -3;
58 pub const LIBSSH2_ERROR_INVALID_MAC: c_int = -4;
59 pub const LIBSSH2_ERROR_KEX_FAILURE: c_int = -5;
60 pub const LIBSSH2_ERROR_ALLOC: c_int = -6;
61 pub const LIBSSH2_ERROR_SOCKET_SEND: c_int = -7;
62 pub const LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE: c_int = -8;
63 pub const LIBSSH2_ERROR_TIMEOUT: c_int = -9;
64 pub const LIBSSH2_ERROR_HOSTKEY_INIT: c_int = -10;
65 pub const LIBSSH2_ERROR_HOSTKEY_SIGN: c_int = -11;
66 pub const LIBSSH2_ERROR_DECRYPT: c_int = -12;
67 pub const LIBSSH2_ERROR_SOCKET_DISCONNECT: c_int = -13;
68 pub const LIBSSH2_ERROR_PROTO: c_int = -14;
69 pub const LIBSSH2_ERROR_PASSWORD_EXPIRED: c_int = -15;
70 pub const LIBSSH2_ERROR_FILE: c_int = -16;
71 pub const LIBSSH2_ERROR_METHOD_NONE: c_int = -17;
72 pub const LIBSSH2_ERROR_AUTHENTICATION_FAILED: c_int = -18;
73 pub const LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: c_int = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
74 pub const LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED: c_int = -19;
75 pub const LIBSSH2_ERROR_CHANNEL_OUTOFORDER: c_int = -20;
76 pub const LIBSSH2_ERROR_CHANNEL_FAILURE: c_int = -21;
77 pub const LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED: c_int = -22;
78 pub const LIBSSH2_ERROR_CHANNEL_UNKNOWN: c_int = -23;
79 pub const LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED: c_int = -24;
80 pub const LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED: c_int = -25;
81 pub const LIBSSH2_ERROR_CHANNEL_CLOSED: c_int = -26;
82 pub const LIBSSH2_ERROR_CHANNEL_EOF_SENT: c_int = -27;
83 pub const LIBSSH2_ERROR_SCP_PROTOCOL: c_int = -28;
84 pub const LIBSSH2_ERROR_ZLIB: c_int = -29;
85 pub const LIBSSH2_ERROR_SOCKET_TIMEOUT: c_int = -30;
86 pub const LIBSSH2_ERROR_SFTP_PROTOCOL: c_int = -31;
87 pub const LIBSSH2_ERROR_REQUEST_DENIED: c_int = -32;
88 pub const LIBSSH2_ERROR_METHOD_NOT_SUPPORTED: c_int = -33;
89 pub const LIBSSH2_ERROR_INVAL: c_int = -34;
90 pub const LIBSSH2_ERROR_INVALID_POLL_TYPE: c_int = -35;
91 pub const LIBSSH2_ERROR_PUBLICKEY_PROTOCOL: c_int = -36;
92 pub const LIBSSH2_ERROR_EAGAIN: c_int = -37;
93 pub const LIBSSH2_ERROR_BUFFER_TOO_SMALL: c_int = -38;
94 pub const LIBSSH2_ERROR_BAD_USE: c_int = -39;
95 pub const LIBSSH2_ERROR_COMPRESS: c_int = -40;
96 pub const LIBSSH2_ERROR_OUT_OF_BOUNDARY: c_int = -41;
97 pub const LIBSSH2_ERROR_AGENT_PROTOCOL: c_int = -42;
98 pub const LIBSSH2_ERROR_SOCKET_RECV: c_int = -43;
99 pub const LIBSSH2_ERROR_ENCRYPT: c_int = -44;
100 pub const LIBSSH2_ERROR_BAD_SOCKET: c_int = -45;
101 pub const LIBSSH2_ERROR_KNOWN_HOSTS: c_int = -46;
102 pub const LIBSSH2_ERROR_CHANNEL_WINDOW_FULL: c_int = -47;
103 pub const LIBSSH2_ERROR_KEYFILE_AUTH_FAILED: c_int = -48;
104 pub const LIBSSH2_ERROR_RANDGEN: c_int = -49;
105 pub const LIBSSH2_ERROR_MISSING_USERAUTH_BANNER: c_int = -50;
106 pub const LIBSSH2_ERROR_ALGO_UNSUPPORTED: c_int = -51;
107
108 pub const LIBSSH2_FX_EOF: c_int = 1;
109 pub const LIBSSH2_FX_NO_SUCH_FILE: c_int = 2;
110 pub const LIBSSH2_FX_PERMISSION_DENIED: c_int = 3;
111 pub const LIBSSH2_FX_FAILURE: c_int = 4;
112 pub const LIBSSH2_FX_BAD_MESSAGE: c_int = 5;
113 pub const LIBSSH2_FX_NO_CONNECTION: c_int = 6;
114 pub const LIBSSH2_FX_CONNECTION_LOST: c_int = 7;
115 pub const LIBSSH2_FX_OP_UNSUPPORTED: c_int = 8;
116 pub const LIBSSH2_FX_INVALID_HANDLE: c_int = 9;
117 pub const LIBSSH2_FX_NO_SUCH_PATH: c_int = 10;
118 pub const LIBSSH2_FX_FILE_ALREADY_EXISTS: c_int = 11;
119 pub const LIBSSH2_FX_WRITE_PROTECT: c_int = 12;
120 pub const LIBSSH2_FX_NO_MEDIA: c_int = 13;
121 pub const LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: c_int = 14;
122 pub const LIBSSH2_FX_QUOTA_EXCEEDED: c_int = 15;
123 pub const LIBSSH2_FX_UNKNOWN_PRINCIPAL: c_int = 16;
124 pub const LIBSSH2_FX_LOCK_CONFLICT: c_int = 17;
125 pub const LIBSSH2_FX_DIR_NOT_EMPTY: c_int = 18;
126 pub const LIBSSH2_FX_NOT_A_DIRECTORY: c_int = 19;
127 pub const LIBSSH2_FX_INVALID_FILENAME: c_int = 20;
128 pub const LIBSSH2_FX_LINK_LOOP: c_int = 21;
129
130 pub const LIBSSH2_HOSTKEY_HASH_MD5: c_int = 1;
131 pub const LIBSSH2_HOSTKEY_HASH_SHA1: c_int = 2;
132 pub const LIBSSH2_HOSTKEY_HASH_SHA256: c_int = 3;
133
134 pub const LIBSSH2_KNOWNHOST_FILE_OPENSSH: c_int = 1;
135
136 pub const LIBSSH2_KNOWNHOST_CHECK_MATCH: c_int = 0;
137 pub const LIBSSH2_KNOWNHOST_CHECK_MISMATCH: c_int = 1;
138 pub const LIBSSH2_KNOWNHOST_CHECK_NOTFOUND: c_int = 2;
139 pub const LIBSSH2_KNOWNHOST_CHECK_FAILURE: c_int = 3;
140
141 pub const LIBSSH2_KNOWNHOST_TYPE_PLAIN: c_int = 1;
142 pub const LIBSSH2_KNOWNHOST_TYPE_SHA1: c_int = 2;
143 pub const LIBSSH2_KNOWNHOST_TYPE_CUSTOM: c_int = 3;
144 pub const LIBSSH2_KNOWNHOST_KEYENC_RAW: c_int = 1 << 16;
145 pub const LIBSSH2_KNOWNHOST_KEYENC_BASE64: c_int = 2 << 16;
146 pub const LIBSSH2_KNOWNHOST_KEY_RSA1: c_int = 1 << 18;
147 pub const LIBSSH2_KNOWNHOST_KEY_SSHRSA: c_int = 2 << 18;
148 pub const LIBSSH2_KNOWNHOST_KEY_SSHDSS: c_int = 3 << 18;
149 pub const LIBSSH2_KNOWNHOST_KEY_ECDSA_256: c_int = 4 << 18;
150 pub const LIBSSH2_KNOWNHOST_KEY_ECDSA_384: c_int = 5 << 18;
151 pub const LIBSSH2_KNOWNHOST_KEY_ECDSA_521: c_int = 6 << 18;
152 pub const LIBSSH2_KNOWNHOST_KEY_ED25519: c_int = 7 << 18;
153 pub const LIBSSH2_KNOWNHOST_KEY_UNKNOWN: c_int = 15 << 18;
154
155 pub const LIBSSH2_FXF_READ: c_ulong = 0x00000001;
156 pub const LIBSSH2_FXF_WRITE: c_ulong = 0x00000002;
157 pub const LIBSSH2_FXF_APPEND: c_ulong = 0x00000004;
158 pub const LIBSSH2_FXF_CREAT: c_ulong = 0x00000008;
159 pub const LIBSSH2_FXF_TRUNC: c_ulong = 0x00000010;
160 pub const LIBSSH2_FXF_EXCL: c_ulong = 0x00000020;
161
162 pub const LIBSSH2_SFTP_OPENFILE: c_int = 0;
163 pub const LIBSSH2_SFTP_OPENDIR: c_int = 1;
164
165 pub const LIBSSH2_SFTP_ATTR_SIZE: c_ulong = 0x00000001;
166 pub const LIBSSH2_SFTP_ATTR_UIDGID: c_ulong = 0x00000002;
167 pub const LIBSSH2_SFTP_ATTR_PERMISSIONS: c_ulong = 0x00000004;
168 pub const LIBSSH2_SFTP_ATTR_ACMODTIME: c_ulong = 0x00000008;
169 pub const LIBSSH2_SFTP_ATTR_EXTENDED: c_ulong = 0x80000000;
170
171 pub const LIBSSH2_SFTP_STAT: c_int = 0;
172 pub const LIBSSH2_SFTP_LSTAT: c_int = 1;
173 pub const LIBSSH2_SFTP_SETSTAT: c_int = 2;
174
175 pub const LIBSSH2_SFTP_SYMLINK: c_int = 0;
176 pub const LIBSSH2_SFTP_READLINK: c_int = 1;
177 pub const LIBSSH2_SFTP_REALPATH: c_int = 2;
178
179 pub const LIBSSH2_SFTP_RENAME_OVERWRITE: c_long = 0x1;
180 pub const LIBSSH2_SFTP_RENAME_ATOMIC: c_long = 0x2;
181 pub const LIBSSH2_SFTP_RENAME_NATIVE: c_long = 0x4;
182
183 pub const LIBSSH2_INIT_NO_CRYPTO: c_int = 0x1;
184
185 pub const LIBSSH2_SFTP_S_IFMT: c_ulong = 0o170000;
186 pub const LIBSSH2_SFTP_S_IFIFO: c_ulong = 0o010000;
187 pub const LIBSSH2_SFTP_S_IFCHR: c_ulong = 0o020000;
188 pub const LIBSSH2_SFTP_S_IFDIR: c_ulong = 0o040000;
189 pub const LIBSSH2_SFTP_S_IFBLK: c_ulong = 0o060000;
190 pub const LIBSSH2_SFTP_S_IFREG: c_ulong = 0o100000;
191 pub const LIBSSH2_SFTP_S_IFLNK: c_ulong = 0o120000;
192 pub const LIBSSH2_SFTP_S_IFSOCK: c_ulong = 0o140000;
193
194 pub const LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL: c_int = 0;
195 pub const LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE: c_int = 1;
196 pub const LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE: c_int = 2;
197
198 pub const LIBSSH2_SESSION_BLOCK_INBOUND: c_int = 1;
199 pub const LIBSSH2_SESSION_BLOCK_OUTBOUND: c_int = 2;
200
201 pub const LIBSSH2_TRACE_TRANS : c_int = 1<<1;
202 pub const LIBSSH2_TRACE_KEX : c_int = 1<<2;
203 pub const LIBSSH2_TRACE_AUTH : c_int = 1<<3;
204 pub const LIBSSH2_TRACE_CONN : c_int = 1<<4;
205 pub const LIBSSH2_TRACE_SCP : c_int = 1<<5;
206 pub const LIBSSH2_TRACE_SFTP : c_int = 1<<6;
207 pub const LIBSSH2_TRACE_ERROR : c_int = 1<<7;
208 pub const LIBSSH2_TRACE_PUBLICKEY : c_int = 1<<8;
209 pub const LIBSSH2_TRACE_SOCKET : c_int = 1<<9;
210 pub enum LIBSSH2_SESSION {}
211 pub enum LIBSSH2_AGENT {}
212 pub enum LIBSSH2_CHANNEL {}
213 pub enum LIBSSH2_LISTENER {}
214 pub enum LIBSSH2_KNOWNHOSTS {}
215 pub enum LIBSSH2_SFTP {}
216 pub enum LIBSSH2_SFTP_HANDLE {}
217
218 pub type libssh2_int64_t = i64;
219 pub 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)]
229 pub struct libssh2_struct_stat(libc::stat);
230
231 impl 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)]
240 pub 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)]
249 pub 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)]
259 pub 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)]
271 pub 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
285 pub type LIBSSH2_ALLOC_FUNC = extern "C" fn(size_t, *mut *mut c_void) -> *mut c_void;
286 pub type LIBSSH2_FREE_FUNC = extern "C" fn(*mut c_void, *mut *mut c_void);
287 pub type LIBSSH2_REALLOC_FUNC = extern "C" fn(*mut c_void, size_t, *mut *mut c_void) -> *mut c_void;
288 pub 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
295 pub 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)]
307 pub 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)]
314 pub struct LIBSSH2_USERAUTH_KBDINT_RESPONSE {
315 pub text: *mut c_char,
316 pub length: c_uint,
317 }
318
319 #[cfg(unix)]
320 pub type libssh2_socket_t = c_int;
321 #[cfg(all(windows, target_pointer_width = "32"))]
322 pub type libssh2_socket_t = u32;
323 #[cfg(all(windows, target_pointer_width = "64"))]
324 pub type libssh2_socket_t = u64;
325
326 extern "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_forward_accept(listener: *mut LIBSSH2_LISTENER) -> *mut LIBSSH2_CHANNEL;
502 pub fn libssh2_channel_forward_cancel(listener: *mut LIBSSH2_LISTENER) -> c_int;
503 pub fn libssh2_channel_forward_listen_ex(
504 sess: *mut LIBSSH2_SESSION,
505 host: *const c_char,
506 port: c_int,
507 bound_port: *mut c_int,
508 queue_maxsize: c_int,
509 ) -> *mut LIBSSH2_LISTENER;
510 pub fn libssh2_channel_handle_extended_data2(
511 channel: *mut LIBSSH2_CHANNEL,
512 mode: c_int,
513 ) -> c_int;
514 pub fn libssh2_channel_request_auth_agent(channel: *mut LIBSSH2_CHANNEL) -> c_int;
515
516 // userauth
517 pub fn libssh2_userauth_banner(sess: *mut LIBSSH2_SESSION, banner: *mut *mut c_char) -> c_int;
518 pub fn libssh2_userauth_authenticated(sess: *mut LIBSSH2_SESSION) -> c_int;
519 pub fn libssh2_userauth_list(
520 sess: *mut LIBSSH2_SESSION,
521 username: *const c_char,
522 username_len: c_uint,
523 ) -> *mut c_char;
524 pub fn libssh2_userauth_hostbased_fromfile_ex(
525 sess: *mut LIBSSH2_SESSION,
526 username: *const c_char,
527 username_len: c_uint,
528 publickey: *const c_char,
529 privatekey: *const c_char,
530 passphrase: *const c_char,
531 hostname: *const c_char,
532 hostname_len: c_uint,
533 local_username: *const c_char,
534 local_len: c_uint,
535 ) -> c_int;
536 pub fn libssh2_userauth_publickey_fromfile_ex(
537 sess: *mut LIBSSH2_SESSION,
538 username: *const c_char,
539 username_len: c_uint,
540 publickey: *const c_char,
541 privatekey: *const c_char,
542 passphrase: *const c_char,
543 ) -> c_int;
544 pub fn libssh2_userauth_publickey_frommemory(
545 sess: *mut LIBSSH2_SESSION,
546 username: *const c_char,
547 username_len: size_t,
548 publickeydata: *const c_char,
549 publickeydata_len: size_t,
550 privatekeydata: *const c_char,
551 privatekeydata_len: size_t,
552 passphrase: *const c_char,
553 ) -> c_int;
554 pub fn libssh2_userauth_password_ex(
555 session: *mut LIBSSH2_SESSION,
556 username: *const c_char,
557 username_len: c_uint,
558 password: *const c_char,
559 password_len: c_uint,
560 password_change_cb: Option<LIBSSH2_PASSWD_CHANGEREQ_FUNC>,
561 ) -> c_int;
562 pub fn libssh2_userauth_keyboard_interactive_ex(
563 session: *mut LIBSSH2_SESSION,
564 username: *const c_char,
565 username_len: c_uint,
566 callback: Option<LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC>,
567 ) -> c_int;
568
569 // knownhost
570 pub fn libssh2_knownhost_free(hosts: *mut LIBSSH2_KNOWNHOSTS);
571 pub fn libssh2_knownhost_addc(
572 hosts: *mut LIBSSH2_KNOWNHOSTS,
573 host: *const c_char,
574 salt: *const c_char,
575 key: *const c_char,
576 keylen: size_t,
577 comment: *const c_char,
578 commentlen: size_t,
579 typemask: c_int,
580 store: *mut *mut libssh2_knownhost,
581 ) -> c_int;
582 pub fn libssh2_knownhost_check(
583 hosts: *mut LIBSSH2_KNOWNHOSTS,
584 host: *const c_char,
585 key: *const c_char,
586 keylen: size_t,
587 typemask: c_int,
588 knownhost: *mut *mut libssh2_knownhost,
589 ) -> c_int;
590 pub fn libssh2_knownhost_checkp(
591 hosts: *mut LIBSSH2_KNOWNHOSTS,
592 host: *const c_char,
593 port: c_int,
594 key: *const c_char,
595 keylen: size_t,
596 typemask: c_int,
597 knownhost: *mut *mut libssh2_knownhost,
598 ) -> c_int;
599 pub fn libssh2_knownhost_del(
600 hosts: *mut LIBSSH2_KNOWNHOSTS,
601 entry: *mut libssh2_knownhost,
602 ) -> c_int;
603 pub fn libssh2_knownhost_get(
604 hosts: *mut LIBSSH2_KNOWNHOSTS,
605 store: *mut *mut libssh2_knownhost,
606 prev: *mut libssh2_knownhost,
607 ) -> c_int;
608 pub fn libssh2_knownhost_readfile(
609 hosts: *mut LIBSSH2_KNOWNHOSTS,
610 filename: *const c_char,
611 kind: c_int,
612 ) -> c_int;
613 pub fn libssh2_knownhost_readline(
614 hosts: *mut LIBSSH2_KNOWNHOSTS,
615 line: *const c_char,
616 len: size_t,
617 kind: c_int,
618 ) -> c_int;
619 pub fn libssh2_knownhost_writefile(
620 hosts: *mut LIBSSH2_KNOWNHOSTS,
621 filename: *const c_char,
622 kind: c_int,
623 ) -> c_int;
624 pub fn libssh2_knownhost_writeline(
625 hosts: *mut LIBSSH2_KNOWNHOSTS,
626 known: *mut libssh2_knownhost,
627 buffer: *mut c_char,
628 buflen: size_t,
629 outlen: *mut size_t,
630 kind: c_int,
631 ) -> c_int;
632 pub fn libssh2_knownhost_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_KNOWNHOSTS;
633
634 // scp
635 #[deprecated(note = "dangerously unsafe on windows, use libssh2_scp_recv2 instead")]
636 pub fn libssh2_scp_recv(
637 sess: *mut LIBSSH2_SESSION,
638 path: *const c_char,
639 sb: *mut libc::stat,
640 ) -> *mut LIBSSH2_CHANNEL;
641
642 pub fn libssh2_scp_recv2(
643 sess: *mut LIBSSH2_SESSION,
644 path: *const c_char,
645 sb: *mut libssh2_struct_stat,
646 ) -> *mut LIBSSH2_CHANNEL;
647
648 pub fn libssh2_scp_send64(
649 sess: *mut LIBSSH2_SESSION,
650 path: *const c_char,
651 mode: c_int,
652 size: libssh2_int64_t,
653 mtime: libc::time_t,
654 atime: libc::time_t,
655 ) -> *mut LIBSSH2_CHANNEL;
656
657 // sftp
658 pub fn libssh2_sftp_init(sess: *mut LIBSSH2_SESSION) -> *mut LIBSSH2_SFTP;
659 pub fn libssh2_sftp_shutdown(sftp: *mut LIBSSH2_SFTP) -> c_int;
660 pub fn libssh2_sftp_last_error(sftp: *mut LIBSSH2_SFTP) -> c_ulong;
661 pub fn libssh2_sftp_open_ex(
662 sftp: *mut LIBSSH2_SFTP,
663 filename: *const c_char,
664 filename_len: c_uint,
665 flags: c_ulong,
666 mode: c_long,
667 open_type: c_int,
668 ) -> *mut LIBSSH2_SFTP_HANDLE;
669 pub fn libssh2_sftp_close_handle(handle: *mut LIBSSH2_SFTP_HANDLE) -> c_int;
670 pub fn libssh2_sftp_mkdir_ex(
671 sftp: *mut LIBSSH2_SFTP,
672 path: *const c_char,
673 path_len: c_uint,
674 mode: c_long,
675 ) -> c_int;
676 pub fn libssh2_sftp_fsync(handle: *mut LIBSSH2_SFTP_HANDLE) -> c_int;
677 pub fn libssh2_sftp_fstat_ex(
678 handle: *mut LIBSSH2_SFTP_HANDLE,
679 attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
680 setstat: c_int,
681 ) -> c_int;
682 pub fn libssh2_sftp_fstatvfs(
683 handle: *mut LIBSSH2_SFTP_HANDLE,
684 attrs: *mut LIBSSH2_SFTP_STATVFS,
685 ) -> c_int;
686 pub fn libssh2_sftp_stat_ex(
687 sftp: *mut LIBSSH2_SFTP,
688 path: *const c_char,
689 path_len: c_uint,
690 stat_type: c_int,
691 attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
692 ) -> c_int;
693 pub fn libssh2_sftp_read(
694 handle: *mut LIBSSH2_SFTP_HANDLE,
695 buf: *mut c_char,
696 len: size_t,
697 ) -> ssize_t;
698 pub fn libssh2_sftp_symlink_ex(
699 sftp: *mut LIBSSH2_SFTP,
700 path: *const c_char,
701 path_len: c_uint,
702 target: *mut c_char,
703 target_len: c_uint,
704 link_type: c_int,
705 ) -> c_int;
706 pub fn libssh2_sftp_rename_ex(
707 sftp: *mut LIBSSH2_SFTP,
708 src: *const c_char,
709 src_len: c_uint,
710 dst: *const c_char,
711 dst_len: c_uint,
712 flags: c_long,
713 ) -> c_int;
714 pub fn libssh2_sftp_rmdir_ex(
715 sftp: *mut LIBSSH2_SFTP,
716 path: *const c_char,
717 path_len: c_uint,
718 ) -> c_int;
719 pub fn libssh2_sftp_write(
720 handle: *mut LIBSSH2_SFTP_HANDLE,
721 buffer: *const c_char,
722 len: size_t,
723 ) -> ssize_t;
724 pub fn libssh2_sftp_tell64(handle: *mut LIBSSH2_SFTP_HANDLE) -> libssh2_uint64_t;
725 pub fn libssh2_sftp_seek64(handle: *mut LIBSSH2_SFTP_HANDLE, off: libssh2_uint64_t);
726 pub fn libssh2_sftp_readdir_ex(
727 handle: *mut LIBSSH2_SFTP_HANDLE,
728 buffer: *mut c_char,
729 buffer_len: size_t,
730 longentry: *mut c_char,
731 longentry_len: size_t,
732 attrs: *mut LIBSSH2_SFTP_ATTRIBUTES,
733 ) -> c_int;
734 pub fn libssh2_sftp_unlink_ex(
735 sftp: *mut LIBSSH2_SFTP,
736 filename: *const c_char,
737 filename_len: c_uint,
738 ) -> c_int;
739 }
740
741 #[test]
742 fn smoke() {
743 unsafe { libssh2_init(0) };
744 }
745
746 #[doc(hidden)]
747 pub fn issue_14344_workaround() {}
748
749 pub fn init() {
750 use std::sync::Once;
751
752 static INIT: Once = Once::new();
753 INIT.call_once(|| unsafe {
754 platform_init();
755 assert_eq!(libc::atexit(shutdown), 0);
756 });
757 extern "C" fn shutdown() {
758 unsafe {
759 libssh2_exit();
760 }
761 }
762
763 #[cfg(unix)]
764 unsafe fn platform_init() {
765 // On Unix we want to funnel through openssl_sys to initialize OpenSSL,
766 // so be sure to tell libssh2 to not do its own thing as we've already
767 // taken care of it.
768 openssl_sys::init();
769 assert_eq!(libssh2_init(LIBSSH2_INIT_NO_CRYPTO), 0);
770 }
771
772 #[cfg(windows)]
773 unsafe fn platform_init() {
774 // On Windows we want to be sure to tell libssh2 to initialize
775 // everything, as we're not managing crypto elsewhere ourselves. Also to
776 // fix alexcrichton/git2-rs#202
777 assert_eq!(libssh2_init(0), 0);
778 }
779 }