24 #if defined _WIN32 || defined __CYGWIN__
30 #define LIBSSH_API __attribute__((dllexport))
32 #define LIBSSH_API __declspec(dllexport)
36 #define LIBSSH_API __attribute__((dllimport))
38 #define LIBSSH_API __declspec(dllimport)
43 #if __GNUC__ >= 4 && !defined(__OS2__)
44 #define LIBSSH_API __attribute__((visibility("default")))
53 typedef unsigned int uint32_t;
54 typedef unsigned short uint16_t;
55 typedef unsigned char uint8_t;
56 typedef unsigned long long uint64_t;
66 #include <sys/select.h>
70 #define SSH_STRINGIFY(s) SSH_TOSTRING(s)
71 #define SSH_TOSTRING(s) #s
74 #define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
75 #define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c
76 #define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c)
79 #define LIBSSH_VERSION_MAJOR 0
80 #define LIBSSH_VERSION_MINOR 6
81 #define LIBSSH_VERSION_MICRO 3
83 #define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
84 LIBSSH_VERSION_MINOR, \
86 #define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \
87 LIBSSH_VERSION_MINOR, \
92 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
94 #define PRINTF_ATTRIBUTE(a,b)
98 #define SSH_DEPRECATED __attribute__ ((deprecated))
100 #define SSH_DEPRECATED
108 typedef struct ssh_agent_struct* ssh_agent;
109 typedef struct ssh_buffer_struct* ssh_buffer;
110 typedef struct ssh_channel_struct* ssh_channel;
111 typedef struct ssh_message_struct* ssh_message;
112 typedef struct ssh_pcap_file_struct* ssh_pcap_file;
113 typedef struct ssh_key_struct* ssh_key;
114 typedef struct ssh_scp_struct* ssh_scp;
115 typedef struct ssh_session_struct* ssh_session;
116 typedef struct ssh_string_struct* ssh_string;
117 typedef struct ssh_event_struct* ssh_event;
118 typedef void* ssh_gssapi_creds;
123 typedef SOCKET socket_t;
127 typedef int socket_t;
131 #define SSH_INVALID_SOCKET ((socket_t) -1)
134 enum ssh_kex_types_e {
162 #define SSH_AUTH_METHOD_UNKNOWN 0
163 #define SSH_AUTH_METHOD_NONE 0x0001
164 #define SSH_AUTH_METHOD_PASSWORD 0x0002
165 #define SSH_AUTH_METHOD_PUBLICKEY 0x0004
166 #define SSH_AUTH_METHOD_HOSTBASED 0x0008
167 #define SSH_AUTH_METHOD_INTERACTIVE 0x0010
168 #define SSH_AUTH_METHOD_GSSAPI_MIC 0x0020
171 enum ssh_requests_e {
173 SSH_REQUEST_CHANNEL_OPEN,
179 enum ssh_channel_type_e {
180 SSH_CHANNEL_UNKNOWN=0,
182 SSH_CHANNEL_DIRECT_TCPIP,
183 SSH_CHANNEL_FORWARDED_TCPIP,
187 enum ssh_channel_requests_e {
188 SSH_CHANNEL_REQUEST_UNKNOWN=0,
189 SSH_CHANNEL_REQUEST_PTY,
190 SSH_CHANNEL_REQUEST_EXEC,
191 SSH_CHANNEL_REQUEST_SHELL,
192 SSH_CHANNEL_REQUEST_ENV,
193 SSH_CHANNEL_REQUEST_SUBSYSTEM,
194 SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
195 SSH_CHANNEL_REQUEST_X11
198 enum ssh_global_requests_e {
199 SSH_GLOBAL_REQUEST_UNKNOWN=0,
200 SSH_GLOBAL_REQUEST_TCPIP_FORWARD,
201 SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD,
204 enum ssh_publickey_state_e {
205 SSH_PUBLICKEY_STATE_ERROR=-1,
206 SSH_PUBLICKEY_STATE_NONE=0,
207 SSH_PUBLICKEY_STATE_VALID=1,
208 SSH_PUBLICKEY_STATE_WRONG=2
213 #define SSH_CLOSED 0x01
215 #define SSH_READ_PENDING 0x02
217 #define SSH_CLOSED_ERROR 0x04
219 #define SSH_WRITE_PENDING 0x08
221 enum ssh_server_known_e {
223 SSH_SERVER_NOT_KNOWN=0,
225 SSH_SERVER_KNOWN_CHANGED,
226 SSH_SERVER_FOUND_OTHER,
227 SSH_SERVER_FILE_NOT_FOUND
230 #ifndef MD5_DIGEST_LEN
231 #define MD5_DIGEST_LEN 16
235 enum ssh_error_types_e {
244 SSH_KEYTYPE_UNKNOWN=0,
252 SSH_KEY_CMP_PUBLIC = 0,
286 #define SSH_LOG_RARE SSH_LOG_WARNING
296 #define SSH_LOG_NONE 0
298 #define SSH_LOG_WARN 1
300 #define SSH_LOG_INFO 2
302 #define SSH_LOG_DEBUG 3
304 #define SSH_LOG_TRACE 4
311 SSH_OPTIONS_PORT_STR,
315 SSH_OPTIONS_IDENTITY,
316 SSH_OPTIONS_ADD_IDENTITY,
317 SSH_OPTIONS_KNOWNHOSTS,
319 SSH_OPTIONS_TIMEOUT_USEC,
322 SSH_OPTIONS_LOG_VERBOSITY,
323 SSH_OPTIONS_LOG_VERBOSITY_STR,
324 SSH_OPTIONS_CIPHERS_C_S,
325 SSH_OPTIONS_CIPHERS_S_C,
326 SSH_OPTIONS_COMPRESSION_C_S,
327 SSH_OPTIONS_COMPRESSION_S_C,
328 SSH_OPTIONS_PROXYCOMMAND,
329 SSH_OPTIONS_BINDADDR,
330 SSH_OPTIONS_STRICTHOSTKEYCHECK,
331 SSH_OPTIONS_COMPRESSION,
332 SSH_OPTIONS_COMPRESSION_LEVEL,
333 SSH_OPTIONS_KEY_EXCHANGE,
334 SSH_OPTIONS_HOSTKEYS,
335 SSH_OPTIONS_GSSAPI_SERVER_IDENTITY,
336 SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY,
337 SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS,
345 SSH_SCP_RECURSIVE=0x10
348 enum ssh_scp_request_types {
350 SSH_SCP_REQUEST_NEWDIR=1,
352 SSH_SCP_REQUEST_NEWFILE,
356 SSH_SCP_REQUEST_ENDDIR,
358 SSH_SCP_REQUEST_WARNING
374 int remoteport,
const char *sourcehost,
int localport);
379 LIBSSH_API
int ssh_channel_read(ssh_channel channel,
void *dest, uint32_t count,
int is_stderr);
380 LIBSSH_API
int ssh_channel_read_timeout(ssh_channel channel,
void *dest, uint32_t count,
int is_stderr,
int timeout_ms);
390 LIBSSH_API
int ssh_channel_request_sftp(ssh_channel channel);
393 const char *cookie,
int screen_number);
395 LIBSSH_API
int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans,
struct
398 LIBSSH_API
int ssh_channel_write(ssh_channel channel,
const void *data, uint32_t len);
399 LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel);
404 LIBSSH_API
const char *ssh_copyright(
void);
410 LIBSSH_API
int ssh_forward_cancel(ssh_session session,
const char *address,
int port);
411 LIBSSH_API
int ssh_forward_listen(ssh_session session,
const char *address,
int port,
int *bound_port);
412 LIBSSH_API
void ssh_free(ssh_session session);
416 LIBSSH_API socket_t
ssh_get_fd(ssh_session session);
417 LIBSSH_API
char *
ssh_get_hexa(
const unsigned char *what,
size_t len);
423 enum ssh_publickey_hash_type {
424 SSH_PUBLICKEY_HASH_SHA1,
425 SSH_PUBLICKEY_HASH_MD5
428 enum ssh_publickey_hash_type type,
429 unsigned char **hash,
432 SSH_DEPRECATED LIBSSH_API
int ssh_get_pubkey_hash(ssh_session session,
unsigned char **hash);
434 LIBSSH_API
int ssh_get_random(
void *where,
int len,
int strong);
448 LIBSSH_API
void _ssh_log(
int verbosity,
449 const char *
function,
450 const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
453 SSH_DEPRECATED LIBSSH_API
void ssh_log(ssh_session session,
455 const
char *format, ...) PRINTF_ATTRIBUTE(3, 4);
457 LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
458 LIBSSH_API
int ssh_message_channel_request_reply_success(ssh_message msg);
463 LIBSSH_API
int ssh_mkdir (const
char *pathname, mode_t mode);
464 LIBSSH_API ssh_session
ssh_new(
void);
469 LIBSSH_API
int ssh_options_set(ssh_session session, enum ssh_options_e type,
471 LIBSSH_API
int ssh_options_get(ssh_session session, enum ssh_options_e type,
474 LIBSSH_API
int ssh_pcap_file_close(ssh_pcap_file pcap);
475 LIBSSH_API
void ssh_pcap_file_free(ssh_pcap_file pcap);
476 LIBSSH_API ssh_pcap_file ssh_pcap_file_new(
void);
477 LIBSSH_API
int ssh_pcap_file_open(ssh_pcap_file pcap, const
char *filename);
492 typedef
int (*ssh_auth_callback) (const
char *prompt,
char *buf,
size_t len,
493 int echo,
int verify,
void *userdata);
497 LIBSSH_API enum ssh_keytypes_e
ssh_key_type(const ssh_key key);
504 enum ssh_keycmp_e what);
509 const
char *passphrase,
510 ssh_auth_callback auth_fn,
514 const
char *passphrase,
515 ssh_auth_callback auth_fn,
519 const
char *passphrase,
520 ssh_auth_callback auth_fn,
522 const
char *filename);
525 enum ssh_keytypes_e type,
534 LIBSSH_API
int ssh_pki_export_pubkey_file(const ssh_key key,
535 const
char *filename);
537 LIBSSH_API
void ssh_print_hexa(const
char *descr, const
unsigned char *what,
size_t len);
538 LIBSSH_API
int ssh_send_ignore (ssh_session session, const
char *data);
539 LIBSSH_API
int ssh_send_debug (ssh_session session, const
char *message,
int always_display);
540 LIBSSH_API
void ssh_gssapi_set_creds(ssh_session session, const ssh_gssapi_creds creds);
547 LIBSSH_API ssh_scp
ssh_scp_new(ssh_session session,
int mode, const
char *location);
550 LIBSSH_API
int ssh_scp_push_file(ssh_scp scp, const
char *filename,
size_t size,
int perms);
551 LIBSSH_API
int ssh_scp_push_file64(ssh_scp scp, const
char *filename, uint64_t size,
int perms);
552 LIBSSH_API
int ssh_scp_read(ssh_scp scp,
void *buffer,
size_t size);
558 LIBSSH_API
int ssh_scp_write(ssh_scp scp, const
void *buffer,
size_t len);
559 LIBSSH_API
int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
560 fd_set *readfds, struct timeval *timeout);
561 LIBSSH_API
int ssh_service_request(ssh_session session, const
char *service);
562 LIBSSH_API
int ssh_set_agent_channel(ssh_session session, ssh_channel channel);
568 LIBSSH_API
int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
574 const
char *username,
575 const ssh_key pubkey);
577 const
char *username,
578 const ssh_key privkey);
581 const char *username);
584 const char *username,
585 const char *passphrase);
587 const char *username,
588 const char *password);
590 LIBSSH_API
int ssh_userauth_kbdint(ssh_session session,
const char *user,
const char *submethods);
600 LIBSSH_API
const char *
ssh_version(
int req_version);
606 LIBSSH_API
int ssh_string_fill(ssh_string str,
const void *data,
size_t len);
615 LIBSSH_API
int ssh_getpass(
const char *prompt,
char *buf,
size_t len,
int echo,
619 typedef int (*ssh_event_callback)(socket_t fd,
int revents,
void *userdata);
623 ssh_event_callback cb,
void *userdata);
634 #ifndef LIBSSH_LEGACY_0_4
635 #include "libssh/legacy.h"