libssh
0.9.5
The SSH library
|
24 #include <libssh/libssh_version.h>
26 #if defined _WIN32 || defined __CYGWIN__
32 #define LIBSSH_API __attribute__((dllexport))
34 #define LIBSSH_API __declspec(dllexport)
38 #define LIBSSH_API __attribute__((dllimport))
40 #define LIBSSH_API __declspec(dllimport)
45 #if __GNUC__ >= 4 && !defined(__OS2__)
46 #define LIBSSH_API __attribute__((visibility("default")))
55 typedef unsigned int uint32_t;
56 typedef unsigned short uint16_t;
57 typedef unsigned char uint8_t;
58 typedef unsigned long long uint64_t;
63 #include <sys/types.h>
69 #include <sys/select.h>
73 #define SSH_STRINGIFY(s) SSH_TOSTRING(s)
74 #define SSH_TOSTRING(s) #s
78 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
80 #define PRINTF_ATTRIBUTE(a,b)
84 #define SSH_DEPRECATED __attribute__ ((deprecated))
86 #define SSH_DEPRECATED
105 typedef struct ssh_pcap_file_struct* ssh_pcap_file;
112 typedef void* ssh_gssapi_creds;
117 typedef SOCKET socket_t;
121 typedef int socket_t;
125 #define SSH_INVALID_SOCKET ((socket_t) -1)
128 enum ssh_kex_types_e {
156 #define SSH_AUTH_METHOD_UNKNOWN 0x0000u
157 #define SSH_AUTH_METHOD_NONE 0x0001u
158 #define SSH_AUTH_METHOD_PASSWORD 0x0002u
159 #define SSH_AUTH_METHOD_PUBLICKEY 0x0004u
160 #define SSH_AUTH_METHOD_HOSTBASED 0x0008u
161 #define SSH_AUTH_METHOD_INTERACTIVE 0x0010u
162 #define SSH_AUTH_METHOD_GSSAPI_MIC 0x0020u
165 enum ssh_requests_e {
167 SSH_REQUEST_CHANNEL_OPEN,
173 enum ssh_channel_type_e {
174 SSH_CHANNEL_UNKNOWN=0,
176 SSH_CHANNEL_DIRECT_TCPIP,
177 SSH_CHANNEL_FORWARDED_TCPIP,
179 SSH_CHANNEL_AUTH_AGENT
182 enum ssh_channel_requests_e {
183 SSH_CHANNEL_REQUEST_UNKNOWN=0,
184 SSH_CHANNEL_REQUEST_PTY,
185 SSH_CHANNEL_REQUEST_EXEC,
186 SSH_CHANNEL_REQUEST_SHELL,
187 SSH_CHANNEL_REQUEST_ENV,
188 SSH_CHANNEL_REQUEST_SUBSYSTEM,
189 SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
190 SSH_CHANNEL_REQUEST_X11
193 enum ssh_global_requests_e {
194 SSH_GLOBAL_REQUEST_UNKNOWN=0,
195 SSH_GLOBAL_REQUEST_TCPIP_FORWARD,
196 SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD,
197 SSH_GLOBAL_REQUEST_KEEPALIVE
200 enum ssh_publickey_state_e {
201 SSH_PUBLICKEY_STATE_ERROR=-1,
202 SSH_PUBLICKEY_STATE_NONE=0,
203 SSH_PUBLICKEY_STATE_VALID=1,
204 SSH_PUBLICKEY_STATE_WRONG=2
209 #define SSH_CLOSED 0x01
211 #define SSH_READ_PENDING 0x02
213 #define SSH_CLOSED_ERROR 0x04
215 #define SSH_WRITE_PENDING 0x08
217 enum ssh_server_known_e {
219 SSH_SERVER_NOT_KNOWN=0,
221 SSH_SERVER_KNOWN_CHANGED,
222 SSH_SERVER_FOUND_OTHER,
223 SSH_SERVER_FILE_NOT_FOUND
226 enum ssh_known_hosts_e {
230 SSH_KNOWN_HOSTS_ERROR = -2,
236 SSH_KNOWN_HOSTS_NOT_FOUND = -1,
242 SSH_KNOWN_HOSTS_UNKNOWN = 0,
254 SSH_KNOWN_HOSTS_CHANGED,
260 SSH_KNOWN_HOSTS_OTHER,
263 #ifndef MD5_DIGEST_LEN
264 #define MD5_DIGEST_LEN 16
268 enum ssh_error_types_e {
277 SSH_KEYTYPE_UNKNOWN=0,
283 SSH_KEYTYPE_DSS_CERT01,
284 SSH_KEYTYPE_RSA_CERT01,
285 SSH_KEYTYPE_ECDSA_P256,
286 SSH_KEYTYPE_ECDSA_P384,
287 SSH_KEYTYPE_ECDSA_P521,
288 SSH_KEYTYPE_ECDSA_P256_CERT01,
289 SSH_KEYTYPE_ECDSA_P384_CERT01,
290 SSH_KEYTYPE_ECDSA_P521_CERT01,
291 SSH_KEYTYPE_ED25519_CERT01,
295 SSH_KEY_CMP_PUBLIC = 0,
299 #define SSH_ADDRSTRLEN 46
339 #define SSH_LOG_RARE SSH_LOG_WARNING
349 #define SSH_LOG_NONE 0
351 #define SSH_LOG_WARN 1
353 #define SSH_LOG_INFO 2
355 #define SSH_LOG_DEBUG 3
357 #define SSH_LOG_TRACE 4
364 SSH_OPTIONS_PORT_STR,
368 SSH_OPTIONS_IDENTITY,
369 SSH_OPTIONS_ADD_IDENTITY,
370 SSH_OPTIONS_KNOWNHOSTS,
372 SSH_OPTIONS_TIMEOUT_USEC,
375 SSH_OPTIONS_LOG_VERBOSITY,
376 SSH_OPTIONS_LOG_VERBOSITY_STR,
377 SSH_OPTIONS_CIPHERS_C_S,
378 SSH_OPTIONS_CIPHERS_S_C,
379 SSH_OPTIONS_COMPRESSION_C_S,
380 SSH_OPTIONS_COMPRESSION_S_C,
381 SSH_OPTIONS_PROXYCOMMAND,
382 SSH_OPTIONS_BINDADDR,
383 SSH_OPTIONS_STRICTHOSTKEYCHECK,
384 SSH_OPTIONS_COMPRESSION,
385 SSH_OPTIONS_COMPRESSION_LEVEL,
386 SSH_OPTIONS_KEY_EXCHANGE,
387 SSH_OPTIONS_HOSTKEYS,
388 SSH_OPTIONS_GSSAPI_SERVER_IDENTITY,
389 SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY,
390 SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS,
391 SSH_OPTIONS_HMAC_C_S,
392 SSH_OPTIONS_HMAC_S_C,
393 SSH_OPTIONS_PASSWORD_AUTH,
394 SSH_OPTIONS_PUBKEY_AUTH,
395 SSH_OPTIONS_KBDINT_AUTH,
396 SSH_OPTIONS_GSSAPI_AUTH,
397 SSH_OPTIONS_GLOBAL_KNOWNHOSTS,
399 SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES,
400 SSH_OPTIONS_PROCESS_CONFIG,
401 SSH_OPTIONS_REKEY_DATA,
402 SSH_OPTIONS_REKEY_TIME,
410 SSH_SCP_RECURSIVE=0x10
413 enum ssh_scp_request_types {
415 SSH_SCP_REQUEST_NEWDIR=1,
417 SSH_SCP_REQUEST_NEWFILE,
421 SSH_SCP_REQUEST_ENDDIR,
423 SSH_SCP_REQUEST_WARNING
426 enum ssh_connector_flags_e {
428 SSH_CONNECTOR_STDOUT = 1,
429 SSH_CONNECTOR_STDINOUT = 1,
431 SSH_CONNECTOR_STDERR = 2,
433 SSH_CONNECTOR_BOTH = 3
449 int remoteport,
const char *sourcehost,
int localport);
451 const char *sourcehost,
int localport);
471 const char *cookie,
int screen_number);
491 LIBSSH_API
int ssh_connector_set_in_channel(
ssh_connector connector,
493 enum ssh_connector_flags_e flags);
494 LIBSSH_API
int ssh_connector_set_out_channel(
ssh_connector connector,
496 enum ssh_connector_flags_e flags);
497 LIBSSH_API
void ssh_connector_set_in_fd(
ssh_connector connector, socket_t fd);
498 LIBSSH_API
void ssh_connector_set_out_fd(
ssh_connector connector, socket_t fd);
500 LIBSSH_API
const char *ssh_copyright(
void);
508 int *destination_port);
522 LIBSSH_API
char *
ssh_get_hexa(
const unsigned char *what,
size_t len);
528 enum ssh_publickey_hash_type {
529 SSH_PUBLICKEY_HASH_SHA1,
530 SSH_PUBLICKEY_HASH_MD5,
531 SSH_PUBLICKEY_HASH_SHA256
534 enum ssh_publickey_hash_type type,
535 unsigned char **hash,
541 SSH_DEPRECATED LIBSSH_API
int ssh_forward_cancel(
ssh_session session,
const char *address,
int port);
542 SSH_DEPRECATED LIBSSH_API
int ssh_forward_listen(
ssh_session session,
const char *address,
int port,
int *bound_port);
547 SSH_DEPRECATED LIBSSH_API
void ssh_print_hexa(
const char *descr,
const unsigned char *what,
size_t len);
551 LIBSSH_API
int ssh_get_random(
void *where,
int len,
int strong);
561 #define SSH_KNOWNHOSTS_ENTRY_FREE(e) do { \
563 ssh_knownhosts_entry_free(e); \
574 char **pentry_string);
586 LIBSSH_API
void _ssh_log(
int verbosity,
587 const char *
function,
588 const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
591 SSH_DEPRECATED LIBSSH_API
void ssh_log(
ssh_session session,
593 const
char *format, ...) PRINTF_ATTRIBUTE(3, 4);
597 LIBSSH_API
int ssh_message_channel_request_reply_success(
ssh_message msg);
598 #define SSH_MESSAGE_FREE(x) \
599 do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
604 LIBSSH_API
int ssh_mkdir (
const char *pathname, mode_t mode);
615 LIBSSH_API
int ssh_pcap_file_close(ssh_pcap_file pcap);
616 LIBSSH_API
void ssh_pcap_file_free(ssh_pcap_file pcap);
617 LIBSSH_API ssh_pcap_file ssh_pcap_file_new(
void);
618 LIBSSH_API
int ssh_pcap_file_open(ssh_pcap_file pcap,
const char *filename);
640 int echo,
int verify,
void *userdata);
645 #define SSH_KEY_FREE(x) \
646 do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
655 enum ssh_keycmp_e what);
660 const char *passphrase,
665 const char *passphrase,
670 const char *passphrase,
675 const char *passphrase,
678 const char *filename);
684 enum ssh_keytypes_e type,
690 enum ssh_keytypes_e type,
699 LIBSSH_API
int ssh_pki_export_pubkey_file(
const ssh_key key,
700 const char *filename);
707 LIBSSH_API
void ssh_print_hash(
enum ssh_publickey_hash_type type,
unsigned char *hash,
size_t len);
710 LIBSSH_API
void ssh_gssapi_set_creds(
ssh_session session,
const ssh_gssapi_creds creds);
730 fd_set *readfds,
struct timeval *timeout);
733 LIBSSH_API
int ssh_set_agent_socket(
ssh_session session, socket_t fd);
741 LIBSSH_API
int ssh_set_pcap_file(
ssh_session session, ssh_pcap_file pcapfile);
747 const char *username,
750 const char *username,
754 const char *username);
757 const char *username,
758 const char *passphrase);
760 const char *username,
761 const char *password);
773 LIBSSH_API
const char *
ssh_version(
int req_version);
779 #define SSH_STRING_FREE(x) \
780 do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
787 #define SSH_STRING_FREE_CHAR(x) \
788 do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
791 LIBSSH_API
int ssh_getpass(
const char *prompt,
char *buf,
size_t len,
int echo,
795 typedef int (*ssh_event_callback)(socket_t fd,
int revents,
void *userdata);
799 ssh_event_callback cb,
void *userdata);
817 #define SSH_BUFFER_FREE(x) \
818 do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
825 #ifndef LIBSSH_LEGACY_0_4
826 #include "libssh/legacy.h"
LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
Import a public key from the given filename.
Definition: pki.c:1584
LIBSSH_API int ssh_mkdir(const char *pathname, mode_t mode)
Attempts to create a directory with the given pathname.
Definition: misc.c:953
Definition: channels.h:62
LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem)
Request a subsystem (for example "sftp").
Definition: channels.c:1941
SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash)
Definition: session.c:975
int ssh_buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint32_t len)
Add data at the tail of a buffer.
Definition: buffer.c:300
LIBSSH_API const char * ssh_userauth_kbdint_getanswer(ssh_session session, unsigned int i)
Get the answer for a question from a message block.
Definition: auth.c:1820
LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct timeval *timeout)
Act like the standard select(2) on channels.
Definition: channels.c:3291
LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol, const char *cookie, int screen_number)
Sends the "x11-req" channel request over an existing session channel.
Definition: channels.c:2042
LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session)
remove the poll handle from session and assign them to a event, when used in blocking mode.
Definition: poll.c:884
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
Reads data from a channel.
Definition: channels.c:2831
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value)
Set environment variables.
Definition: channels.c:2498
LIBSSH_API int ssh_pki_import_privkey_base64(const char *b64_key, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, ssh_key *pkey)
import a base64 formated key from a memory c-string
Definition: pki.c:730
LIBSSH_API int ssh_channel_send_eof(ssh_channel channel)
Send an end of file on the channel.
Definition: channels.c:1224
LIBSSH_API int ssh_send_debug(ssh_session session, const char *message, int always_display)
Send a debug message.
Definition: session.c:908
LIBSSH_API const char * ssh_key_type_to_char(enum ssh_keytypes_e type)
Convert a key type to a string.
Definition: pki.c:271
LIBSSH_API int ssh_channel_open_forward_unix(ssh_channel channel, const char *remotepath, const char *sourcehost, int localport)
Open a TCP/IP - UNIX domain socket forwarding channel.
Definition: channels.c:1057
LIBSSH_API int ssh_channel_open_session(ssh_channel channel)
Open a session channel (suited for a shell, not TCP forwarding).
Definition: channels.c:920
char * ssh_string_to_char(struct ssh_string_struct *s)
Convert a SSH string to a C nul-terminated string.
Definition: string.c:181
LIBSSH_API enum ssh_known_hosts_e ssh_session_has_known_hosts_entry(ssh_session session)
Check if the set hostname and port matches an entry in known_hosts.
Definition: knownhosts.c:777
LIBSSH_API int ssh_scp_close(ssh_scp scp)
Close the scp channel.
Definition: scp.c:241
LIBSSH_API int ssh_event_add_fd(ssh_event event, socket_t fd, short events, ssh_event_callback cb, void *userdata)
Add a fd to the event and assign it a callback, when used in blocking mode.
Definition: poll.c:815
LIBSSH_API void ssh_print_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len)
Print a hash as a human-readable hex- or base64-string.
Definition: dh.c:789
LIBSSH_API int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size, int perms)
Initialize the sending of a file to a scp in sink mode, using a 64-bit size.
Definition: scp.c:456
LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest)
Duplicate the options of a session structure.
Definition: options.c:65
LIBSSH_API void ssh_channel_free(ssh_channel channel)
Close and free a channel.
Definition: channels.c:1123
LIBSSH_API uint64_t ssh_scp_request_get_size64(ssh_scp scp)
Get the size of the file being pushed from the other party.
Definition: scp.c:1066
LIBSSH_API int ssh_channel_close(ssh_channel channel)
Close a channel.
Definition: channels.c:1285
LIBSSH_API int ssh_session_export_known_hosts_entry(ssh_session session, char **pentry_string)
Export the current session information to a known_hosts string.
Definition: knownhosts.c:892
LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel, const void *data, uint32_t len)
Blocking write on a channel stderr.
Definition: channels.c:3445
SSH_DEPRECATED LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key)
Definition: session.c:1087
LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel)
Get the remote window size.
Definition: channels.c:1536
LIBSSH_API int ssh_is_connected(ssh_session session)
Check if we are connected.
Definition: session.c:550
@ SSH_LOG_PACKET
Definition: libssh.h:333
LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking)
Set the session in blocking/nonblocking mode.
Definition: session.c:484
LIBSSH_API ssh_event ssh_event_new(void)
Create a new event context. It could be associated with many ssh_session objects and socket fd which ...
Definition: poll.c:760
LIBSSH_API int ssh_pki_export_privkey_file(const ssh_key privkey, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, const char *filename)
Export a private key to a pem file on disk, or OpenSSH format for keytype ssh-ed25519.
Definition: pki.c:944
LIBSSH_API int ssh_pki_export_pubkey_base64(const ssh_key key, char **b64_key)
Convert a public key to a base64 encoded key.
Definition: pki.c:1916
LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms)
Initialize the sending of a file to a scp in sink mode.
Definition: scp.c:557
LIBSSH_API void ssh_set_fd_except(ssh_session session)
Tell the session it has an exception to catch on the file descriptor.
Definition: session.c:608
Definition: connector.c:52
LIBSSH_API int ssh_channel_cancel_forward(ssh_session session, const char *address, int port)
Sends the "cancel-tcpip-forward" global request to ask the server to cancel the tcpip-forward request...
Definition: channels.c:2447
LIBSSH_API int ssh_key_is_public(const ssh_key k)
Check if the key has/is a public key.
Definition: pki.c:585
LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode)
Create a directory in a scp in sink mode.
Definition: scp.c:320
Definition: messages.h:46
LIBSSH_API int ssh_key_is_private(const ssh_key k)
Check if the key is a private key.
Definition: pki.c:600
LIBSSH_API ssh_string ssh_string_new(size_t size)
Create a new SSH String object.
Definition: string.c:56
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr)
Polls a channel for data to read.
Definition: channels.c:3039
LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i, const char *answer)
Set the answer for a question from a message block.
Definition: auth.c:1851
@ SSH_LOG_WARNING
Definition: libssh.h:327
void ssh_buffer_free(struct ssh_buffer_struct *buffer)
Deallocate a SSH buffer.
Definition: buffer.c:149
LIBSSH_API int ssh_get_version(ssh_session session)
Get the protocol version of the session.
Definition: session.c:838
LIBSSH_API ssh_string ssh_string_from_char(const char *what)
Create a ssh string using a C string.
Definition: string.c:108
LIBSSH_API void ssh_scp_free(ssh_scp scp)
Free a scp context.
Definition: scp.c:286
LIBSSH_API void ssh_disconnect(ssh_session session)
Disconnect from a session (client or server). The session can then be reused to open a new session.
Definition: client.c:692
LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms)
Reads data from a channel.
Definition: channels.c:2863
LIBSSH_API enum ssh_known_hosts_e ssh_session_get_known_hosts_entry(ssh_session session, struct ssh_knownhosts_entry **pentry)
Get the known_hosts entry for the current connected session.
Definition: knownhosts.c:1130
LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term, int cols, int rows)
Request a pty with a specific type and size.
Definition: channels.c:1798
Definition: messages.h:84
LIBSSH_API const char * ssh_get_cipher_in(ssh_session session)
get the name of the input cipher for the given session.
Definition: session.c:405
@ SSH_LOG_NOLOG
Definition: libssh.h:324
LIBSSH_API ssh_channel ssh_channel_new(ssh_session session)
Allocate a new channel.
Definition: channels.c:80
LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter, ssh_counter rcounter)
Set the session data counters.
Definition: session.c:964
int ssh_string_fill(struct ssh_string_struct *s, const void *data, size_t len)
Fill a string with given data. The string should be big enough.
Definition: string.c:87
LIBSSH_API int ssh_pki_generate(enum ssh_keytypes_e type, int parameter, ssh_key *pkey)
Generates a keypair.
Definition: pki.c:1758
LIBSSH_API int ssh_message_subtype(ssh_message msg)
Get the subtype of the message.
Definition: messages.c:558
LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size)
Read from a remote scp file.
Definition: scp.c:956
struct ssh_string_struct * ssh_string_copy(struct ssh_string_struct *s)
Copy a string, return a newly allocated string. The caller has to free the string.
Definition: string.c:221
LIBSSH_API int ssh_get_poll_flags(ssh_session session)
Get poll flags for an external mainloop.
Definition: session.c:793
LIBSSH_API enum ssh_keytypes_e ssh_key_type_from_name(const char *name)
Convert a ssh key name to a ssh key type.
Definition: pki.c:512
LIBSSH_API const char * ssh_userauth_kbdint_getinstruction(ssh_session session)
Get the "instruction" of the message block.
Definition: auth.c:1741
LIBSSH_API int ssh_scp_accept_request(ssh_scp scp)
Accepts transfer of a file or creation of a directory coming from the remote party.
Definition: scp.c:918
LIBSSH_API int ssh_init(void)
Initialize global cryptographic data structures.
Definition: init.c:153
void * ssh_buffer_get(struct ssh_buffer_struct *buffer)
Get a pointer to the head of a buffer at the current position.
Definition: buffer.c:594
LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel)
Recover the session in which belongs a channel.
Definition: channels.c:3151
LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout)
A wrapper for the select syscall.
Definition: connect.c:316
LIBSSH_API int ssh_get_error_code(void *error)
Retrieve the error code from the last error.
Definition: error.c:148
LIBSSH_API socket_t ssh_get_fd(ssh_session session)
Get the fd of a connection.
Definition: session.c:568
LIBSSH_API const char * ssh_get_error(void *error)
Retrieve the error text message from the last error.
Definition: error.c:128
LIBSSH_API int ssh_finalize(void)
Finalize and cleanup all libssh and cryptographic data structures.
Definition: init.c:229
LIBSSH_API int ssh_pki_copy_cert_to_privkey(const ssh_key cert_key, ssh_key privkey)
Copy the certificate part of a public key into a private key.
Definition: pki.c:2009
LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session, const char *username, const char *passphrase)
Tries to automatically authenticate with public key and "none".
Definition: auth.c:1007
SSH_DEPRECATED LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len)
Definition: misc.c:431
LIBSSH_API int ssh_known_hosts_parse_line(const char *host, const char *line, struct ssh_knownhosts_entry **entry)
Parse a line from a known_hosts entry into a structure.
Definition: knownhosts.c:612
uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer)
Get the length of the buffer from the current position.
Definition: buffer.c:607
int ssh_buffer_reinit(struct ssh_buffer_struct *buffer)
Reinitialize a SSH buffer.
Definition: buffer.c:259
LIBSSH_API int ssh_get_server_publickey(ssh_session session, ssh_key *key)
Get the server public key from a session.
Definition: session.c:1065
LIBSSH_API int ssh_options_get_port(ssh_session session, unsigned int *port_target)
This function can get ssh the ssh port. It must only be used on a valid ssh session....
Definition: options.c:1055
LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd)
Remove a socket fd from an event context.
Definition: poll.c:976
LIBSSH_API int ssh_event_add_connector(ssh_event event, ssh_connector connector)
Add a connector to the SSH event loop.
Definition: poll.c:936
LIBSSH_API int ssh_channel_request_send_break(ssh_channel channel, uint32_t length)
Send a break signal to the server (as described in RFC 4335).
Definition: channels.c:2684
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel)
Check if remote has sent an EOF.
Definition: channels.c:1596
LIBSSH_API int ssh_userauth_agent(ssh_session session, const char *username)
Try to do public key authentication with ssh agent.
Definition: auth.c:872
SSH_DEPRECATED LIBSSH_API int ssh_write_knownhost(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:499
int(* ssh_auth_callback)(const char *prompt, char *buf, size_t len, int echo, int verify, void *userdata)
SSH authentication callback for password and publickey auth.
Definition: libssh.h:639
LIBSSH_API void ssh_key_free(ssh_key key)
deallocate a SSH key
Definition: pki.c:193
LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking)
Put the channel into blocking or nonblocking mode.
Definition: channels.c:1621
LIBSSH_API const char * ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo)
Get a prompt from a message block.
Definition: auth.c:1776
LIBSSH_API void ssh_set_fd_towrite(ssh_session session)
Tell the session it may write to the file descriptor without blocking.
Definition: session.c:595
LIBSSH_API void ssh_channel_set_counter(ssh_channel channel, ssh_counter counter)
Set the channel data counter.
Definition: channels.c:3425
const char * ssh_string_get_char(struct ssh_string_struct *s)
Get the the string as a C nul-terminated string.
Definition: string.c:160
Definition: session.h:109
LIBSSH_API int ssh_channel_is_closed(ssh_channel channel)
Check if the channel is closed or not.
Definition: channels.c:1582
LIBSSH_API int ssh_get_openssh_version(ssh_session session)
Get the version of the OpenSSH server, if it is not an OpenSSH server then 0 will be returned.
Definition: client.c:678
LIBSSH_API int ssh_channel_open_auth_agent(ssh_channel channel)
Open an agent authentication forwarding channel. This type of channel can be opened by a server towar...
Definition: channels.c:947
LIBSSH_API const char * ssh_scp_request_get_warning(ssh_scp scp)
Get the warning string from a scp handle.
Definition: scp.c:1110
LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username)
Get available authentication methods from the server.
Definition: auth.c:376
LIBSSH_API const char * ssh_get_serverbanner(ssh_session session)
get the server banner
Definition: session.c:350
LIBSSH_API char * ssh_basename(const char *path)
basename - parse filename component.
Definition: misc.c:902
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len)
Blocking write on a channel.
Definition: channels.c:1553
LIBSSH_API enum ssh_known_hosts_e ssh_session_is_known_server(ssh_session session)
Check if the servers public key for the connected session is known.
Definition: knownhosts.c:1255
@ SSH_LOG_FUNCTIONS
Definition: libssh.h:336
LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum)
Send a signal to remote process (as described in RFC 4254, section 6.9).
Definition: channels.c:2638
LIBSSH_API ssh_buffer ssh_buffer_new(void)
Create a new SSH buffer.
Definition: buffer.c:119
LIBSSH_API int ssh_event_remove_connector(ssh_event event, ssh_connector connector)
Remove a connector from an event context.
Definition: poll.c:1076
LIBSSH_API void ssh_set_fd_toread(ssh_session session)
Tell the session it has data to read on the file descriptor without blocking.
Definition: session.c:582
LIBSSH_API int ssh_userauth_publickey(ssh_session session, const char *username, const ssh_key privkey)
Authenticate with public/private key or certificate.
Definition: auth.c:609
LIBSSH_API int ssh_pki_import_cert_base64(const char *b64_cert, enum ssh_keytypes_e type, ssh_key *pkey)
Import a base64 formated certificate from a memory c-string.
Definition: pki.c:1699
LIBSSH_API const char * ssh_get_clientbanner(ssh_session session)
get the client banner
Definition: session.c:335
LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len)
Write into a remote scp file.
Definition: scp.c:642
LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel)
Get the exit status of the channel (error code from the executed instruction).
Definition: channels.c:3187
LIBSSH_API int ssh_scp_pull_request(ssh_scp scp)
Wait for a scp request (file, directory).
Definition: scp.c:770
LIBSSH_API int ssh_channel_listen_forward(ssh_session session, const char *address, int port, int *bound_port)
Sends the "tcpip-forward" global request to ask the server to begin listening for inbound connections...
Definition: channels.c:2365
LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms)
Accept an X11 forwarding channel.
Definition: channels.c:2158
LIBSSH_API const char * ssh_get_kex_algo(ssh_session session)
get the name of the current key exchange algorithm.
Definition: session.c:364
LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp)
Leave a directory.
Definition: scp.c:409
LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session)
Get the number of prompts (questions) the server has given.
Definition: auth.c:1696
SSH_DEPRECATED LIBSSH_API int ssh_is_server_known(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:288
LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason)
Deny the transfer of a file or creation of a directory coming from the remote party.
Definition: scp.c:882
LIBSSH_API int ssh_send_ignore(ssh_session session, const char *data)
Send a message that should be ignored.
Definition: session.c:873
LIBSSH_API int ssh_connect(ssh_session session)
Connect to the ssh server.
Definition: client.c:508
LIBSSH_API char * ssh_get_hexa(const unsigned char *what, size_t len)
Convert a buffer into a colon separated hex string. The caller has to free the memory.
Definition: misc.c:403
LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd)
Run a shell command without an interactive shell.
Definition: channels.c:2568
LIBSSH_API const char * ssh_get_disconnect_message(ssh_session session)
Get the disconnect message from the server.
Definition: session.c:813
LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp)
Get the permissions of the directory or file being pushed from the other party.
Definition: scp.c:1038
LIBSSH_API char * ssh_get_issue_banner(ssh_session session)
Get the issue banner from the server.
Definition: client.c:652
LIBSSH_API const char * ssh_pki_key_ecdsa_name(const ssh_key key)
returns the ECDSA key name ("ecdsa-sha2-nistp256" for example)
Definition: pki.c:101
LIBSSH_API enum ssh_keytypes_e ssh_key_type(const ssh_key key)
returns the type of a ssh key
Definition: pki.c:211
LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout)
Poll all the sockets and sessions associated through an event object.i.
Definition: poll.c:957
uint32_t ssh_buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len)
Get the remaining data out of the buffer and adjust the read pointer.
Definition: buffer.c:676
LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username)
Try to authenticate through the "none" method.
Definition: auth.c:406
LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr, int orig_port)
Open a X11 channel.
Definition: channels.c:3538
LIBSSH_API ssh_session ssh_new(void)
Create a new ssh session.
Definition: session.c:59
LIBSSH_API int ssh_key_cmp(const ssh_key k1, const ssh_key k2, enum ssh_keycmp_e what)
Compare keys if they are equal.
Definition: pki.c:619
LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods)
Try to authenticate through the "keyboard-interactive" method.
Definition: auth.c:1653
void * ssh_string_data(struct ssh_string_struct *s)
Get the payload of the string.
Definition: string.c:264
LIBSSH_API void ssh_knownhosts_entry_free(struct ssh_knownhosts_entry *entry)
Free an allocated ssh_knownhosts_entry.
Definition: knownhosts.c:145
LIBSSH_API int ssh_channel_request_pty(ssh_channel channel)
Request a PTY.
Definition: channels.c:1861
LIBSSH_API ssh_key ssh_key_new(void)
creates a new empty SSH key
Definition: pki.c:118
LIBSSH_API int ssh_channel_is_open(ssh_channel channel)
Check if the channel is open or not.
Definition: channels.c:1566
LIBSSH_API int ssh_pki_import_cert_file(const char *filename, ssh_key *pkey)
Import a certificate from the given filename.
Definition: pki.c:1738
LIBSSH_API char * ssh_get_fingerprint_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len)
Get a hash as a human-readable hex- or base64-string.
Definition: dh.c:717
LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows)
Change the size of the terminal associated to a channel.
Definition: channels.c:1880
LIBSSH_API int ssh_is_blocking(ssh_session session)
Return the blocking mode of libssh.
Definition: session.c:499
LIBSSH_API int ssh_get_log_level(void)
Get the log level of the library.
Definition: log.c:196
void ssh_string_free(struct ssh_string_struct *s)
Deallocate a SSH string object.
Definition: string.c:277
LIBSSH_API char * ssh_dirname(const char *path)
Parse directory component.
Definition: misc.c:847
LIBSSH_API int ssh_get_publickey_hash(const ssh_key key, enum ssh_publickey_hash_type type, unsigned char **hash, size_t *hlen)
Allocates a buffer with the hash of the public key.
Definition: session.c:1120
size_t ssh_string_len(struct ssh_string_struct *s)
Return the size of a SSH string.
Definition: string.c:136
LIBSSH_API const char * ssh_get_hmac_out(ssh_session session)
get the name of the output HMAC algorithm for the given session.
Definition: session.c:452
void ssh_string_burn(struct ssh_string_struct *s)
Destroy the data in a string so it couldn't appear in a core dump.
Definition: string.c:249
LIBSSH_API int ssh_pki_export_privkey_base64(const ssh_key privkey, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, char **b64_key)
Convert a private key to a pem base64 encoded key, or OpenSSH format for keytype ssh-ed25519.
Definition: pki.c:791
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
This function can set all possible ssh options.
Definition: options.c:474
LIBSSH_API int ssh_session_update_known_hosts(ssh_session session)
Add the current connected server to the user known_hosts file.
Definition: knownhosts.c:965
LIBSSH_API void ssh_event_free(ssh_event event)
Free an event context.
Definition: poll.c:1089
LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session, int timeout_ms, int *destination_port)
Accept an incoming TCP/IP forwarding channel and get information about incomming connection.
Definition: channels.c:2428
LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location)
Create a new scp session.
Definition: scp.c:61
LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password)
Try to authenticate by password.
Definition: auth.c:1235
LIBSSH_API int ssh_userauth_kbdint_getnanswers(ssh_session session)
Get the number of answers the client has given.
Definition: auth.c:1804
LIBSSH_API void ssh_free(ssh_session session)
Deallocate a SSH session handle.
Definition: session.c:191
LIBSSH_API const char * ssh_get_cipher_out(ssh_session session)
get the name of the output cipher for the given session.
Definition: session.c:421
LIBSSH_API void * ssh_get_log_userdata(void)
Get the userdata of the logging function.
Definition: log.c:219
LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr)
Polls a channel for data to read, waiting for a certain timeout.
Definition: channels.c:3091
LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
Parse command line arguments.
Definition: options.c:1193
LIBSSH_API int ssh_set_log_userdata(void *data)
Set the userdata for the logging function.
Definition: log.c:235
LIBSSH_API int ssh_channel_request_shell(ssh_channel channel)
Request a shell.
Definition: channels.c:1919
LIBSSH_API int ssh_channel_request_auth_agent(ssh_channel channel)
Send an "auth-agent-req" channel request over an existing session channel.
Definition: channels.c:2173
LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp)
Get the size of the file being pushed from the other party.
Definition: scp.c:1054
LIBSSH_API void ssh_string_free_char(char *s)
Deallocate a char string object.
Definition: string.c:209
LIBSSH_API int ssh_userauth_try_publickey(ssh_session session, const char *username, const ssh_key pubkey)
Try to authenticate with the given public key.
Definition: auth.c:489
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
Do a nonblocking read on the channel.
Definition: channels.c:2984
LIBSSH_API int ssh_options_get(ssh_session session, enum ssh_options_e type, char **value)
This function can get ssh options, it does not support all options provided for ssh options set,...
Definition: options.c:1113
LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session)
Remove a session object from an event context.
Definition: poll.c:1022
LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost, int remoteport, const char *sourcehost, int localport)
Open a TCP/IP forwarding channel.
Definition: channels.c:985
LIBSSH_API int ssh_pki_import_privkey_file(const char *filename, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, ssh_key *pkey)
Import a key from a file.
Definition: pki.c:850
LIBSSH_API void ssh_silent_disconnect(ssh_session session)
Disconnect impolitely from a remote host by closing the socket.
Definition: session.c:467
LIBSSH_API int ssh_scp_init(ssh_scp scp)
Initialize the scp channel.
Definition: scp.c:119
LIBSSH_API int ssh_message_type(ssh_message msg)
Get the type of the message.
Definition: messages.c:543
LIBSSH_API const char * ssh_scp_request_get_filename(ssh_scp scp)
Get the name of the directory or file being pushed from the other party.
Definition: scp.c:1023
LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel)
Request sftp subsystem on the channel.
Definition: channels.c:1990
LIBSSH_API const char * ssh_version(int req_version)
Check if libssh is the required version or get the version string.
Definition: misc.c:652
LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout)
Blocking flush of the outgoing buffer.
Definition: session.c:525
LIBSSH_API int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey, ssh_key *pkey)
Create a public key from a private key.
Definition: pki.c:1848
LIBSSH_API int ssh_userauth_gssapi(ssh_session session)
Try to authenticate through the "gssapi-with-mic" method.
Definition: auth.c:1898
LIBSSH_API const char * ssh_userauth_kbdint_getname(ssh_session session)
Get the "name" of the message block.
Definition: auth.c:1718
LIBSSH_API int ssh_get_status(ssh_session session)
Get session status.
Definition: session.c:755
SSH_DEPRECATED LIBSSH_API char * ssh_dump_knownhost(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:430
LIBSSH_API const char * ssh_get_hmac_in(ssh_session session)
get the name of the input HMAC algorithm for the given session.
Definition: session.c:437
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename)
Parse the ssh config file.
Definition: options.c:1375
LIBSSH_API int ssh_set_log_level(int level)
Set the log level of the library.
Definition: log.c:181
LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key, enum ssh_keytypes_e type, ssh_key *pkey)
Import a base64 formated public key from a memory c-string.
Definition: pki.c:1470
LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash)
Deallocate the hash obtained by ssh_get_pubkey_hash.
Definition: session.c:1049
LIBSSH_API void ssh_message_free(ssh_message msg)
Free a SSH message.
Definition: messages.c:582
LIBSSH_API ssh_message ssh_message_get(ssh_session session)
Retrieve a SSH message from a SSH session.
Definition: messages.c:516
@ SSH_LOG_PROTOCOL
Definition: libssh.h:330
LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo, int verify)
Get a password from the console.
Definition: getpass.c:212