functions that manage a session More...
Functions | |
void | ssh_clean_pubkey_hash (unsigned char **hash) |
Deallocate the hash obtained by ssh_get_pubkey_hash. | |
int | ssh_connect (ssh_session session) |
connect to the ssh server | |
void | ssh_disconnect (ssh_session session) |
Disconnect from a session (client or server). | |
int | ssh_finalize (void) |
Finalize and cleanup all libssh and cryptographic data structures. | |
void | ssh_free (ssh_session session) |
deallocate a session handle | |
const char * | ssh_get_disconnect_message (ssh_session session) |
get the disconnect message from the server | |
socket_t | ssh_get_fd (ssh_session session) |
In case you'd need the file descriptor of the connection to the server/client. | |
char * | ssh_get_issue_banner (ssh_session session) |
Get the issue banner from the server. | |
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. | |
int | ssh_get_pubkey_hash (ssh_session session, unsigned char **hash) |
Allocates a buffer with the MD5 hash of the server public key. | |
int | ssh_get_status (ssh_session session) |
Get session status. | |
int | ssh_get_version (ssh_session session) |
Get the protocol version of the session. | |
int | ssh_handle_packets (ssh_session session) |
int | ssh_init (void) |
initialize global cryptographic data structures. | |
int | ssh_is_server_known (ssh_session session) |
Check if the server is known. | |
ssh_session | ssh_new (void) |
creates a new ssh session | |
int | ssh_options_copy (ssh_session src, ssh_session *dest) |
Duplicate the options of a session structure. | |
int | ssh_options_set (ssh_session session, enum ssh_options_e type, const void *value) |
This function can set all possible ssh options. | |
int | ssh_select (ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout) |
A wrapper for the select syscall. | |
void | ssh_set_blocking (ssh_session session, int blocking) |
set the session in blocking/nonblocking mode | |
void | ssh_set_fd_except (ssh_session session) |
say the session it has an exception to catch on the file descriptor | |
void | ssh_set_fd_toread (ssh_session session) |
say to the session it has data to read on the file descriptor without blocking | |
void | ssh_set_fd_towrite (ssh_session session) |
say the session it may write to the file descriptor without blocking | |
void | ssh_silent_disconnect (ssh_session session) |
disconnect impolitely from remote host by closing the socket. | |
int | ssh_write_knownhost (ssh_session session) |
You generaly use it when ssh_is_server_known() answered SSH_SERVER_NOT_KNOWN. |
functions that manage a session
void ssh_clean_pubkey_hash | ( | unsigned char ** | hash | ) |
Deallocate the hash obtained by ssh_get_pubkey_hash.
This is required under Microsoft platform as this library might use a different C library than your software, hence a different heap.
hash | The buffer to deallocate. |
int ssh_connect | ( | ssh_session | session | ) |
connect to the ssh server
session | ssh session |
References ssh_init(), ssh_log(), and SSH_LOG_RARE.
void ssh_disconnect | ( | ssh_session | session | ) |
Disconnect from a session (client or server).
The session can then be reused to open a new session.
session | The SSH session to disconnect. |
References string_free(), and string_from_char().
Referenced by ssh_silent_disconnect().
int ssh_finalize | ( | void | ) |
Finalize and cleanup all libssh and cryptographic data structures.
This function should only be called once, at the end of the program!
void ssh_free | ( | ssh_session | session | ) |
deallocate a session handle
References buffer_free(), channel_free(), and privatekey_free().
Referenced by ssh_new().
const char* ssh_get_disconnect_message | ( | ssh_session | session | ) |
get the disconnect message from the server
session | ssh session |
socket_t ssh_get_fd | ( | ssh_session | session | ) |
In case you'd need the file descriptor of the connection to the server/client.
recover the fd of connection
session | ssh session |
char* ssh_get_issue_banner | ( | ssh_session | session | ) |
Get the issue banner from the server.
This is the banner showing a disclaimer to users who log in, typically their right or the fact that they will be monitored.
session | The SSH session to use. |
References string_to_char().
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.
You can use the SSH_VERSION_INT macro to compare version numbers.
session | The SSH session to use. |
int ssh_get_pubkey_hash | ( | ssh_session | session, | |
unsigned char ** | hash | |||
) |
Allocates a buffer with the MD5 hash of the server public key.
session | The SSH session to use. | |
hash | The buffer to allocate. |
References string_len().
int ssh_get_status | ( | ssh_session | session | ) |
Get session status.
session | The ssh session to use. |
int ssh_get_version | ( | ssh_session | session | ) |
Get the protocol version of the session.
session | The ssh session to use. |
int ssh_handle_packets | ( | ssh_session | session | ) |
Referenced by channel_poll().
int ssh_init | ( | void | ) |
initialize global cryptographic data structures.
This function should only be called once, at the beginning of the program, in the main thread. It may be omitted if your program is not multithreaded.
Referenced by ssh_bind_listen(), and ssh_connect().
int ssh_is_server_known | ( | ssh_session | session | ) |
Check if the server is known.
Checks the user's known host file for a previous connection to the current server.
session | ssh session |
References ssh_options_set().
ssh_session ssh_new | ( | void | ) |
int ssh_options_copy | ( | ssh_session | src, | |
ssh_session * | dest | |||
) |
Duplicate the options of a session structure.
If you make several sessions with the same options this is useful. You cannot use twice the same option structure in ssh_session_connect.
src | The session to use to copy the options. | |
dest | The session to copy the options to. |
int ssh_options_set | ( | ssh_session | session, | |
enum ssh_options_e | type, | |||
const void * | value | |||
) |
This function can set all possible ssh options.
session | An allocated ssh option structure. | |
type | The option type to set. This could be one of the following: |
fn(void *arg, float status)
value | The value to set. This is a generic pointer and the datatype which is used should be set according to the type set. |
Referenced by ssh_is_server_known(), ssh_try_publickey_from_file(), ssh_userauth_agent_pubkey(), ssh_userauth_kbdint(), ssh_userauth_none(), ssh_userauth_offer_pubkey(), ssh_userauth_password(), ssh_userauth_pubkey(), and ssh_write_knownhost().
int ssh_select | ( | ssh_channel * | channels, | |
ssh_channel * | outchannels, | |||
socket_t | maxfd, | |||
fd_set * | readfds, | |||
struct timeval * | timeout | |||
) |
A wrapper for the select syscall.
This functions acts more or less like the select(2) syscall.
There is no support for writing or exceptions.
channels | Arrays of channels pointers terminated by a NULL. It is never rewritten. | |
outchannels | Arrays of same size that "channels", there is no need to initialize it. | |
maxfd | Maximum +1 file descriptor from readfds. | |
readfds | A fd_set of file descriptors to be select'ed for reading. | |
timeout | A timeout for the select. |
References channel_poll().
void ssh_set_blocking | ( | ssh_session | session, | |
int | blocking | |||
) |
set the session in blocking/nonblocking mode
session | ssh session | |
blocking | zero for nonblocking mode |
void ssh_set_fd_except | ( | ssh_session | session | ) |
say the session it has an exception to catch on the file descriptor
session | ssh session |
void ssh_set_fd_toread | ( | ssh_session | session | ) |
say to the session it has data to read on the file descriptor without blocking
session | ssh session |
void ssh_set_fd_towrite | ( | ssh_session | session | ) |
say the session it may write to the file descriptor without blocking
session | ssh session |
void ssh_silent_disconnect | ( | ssh_session | session | ) |
disconnect impolitely from remote host by closing the socket.
Suitable if you forked and want to destroy this session.
session | current ssh session |
References ssh_disconnect().
int ssh_write_knownhost | ( | ssh_session | session | ) |
You generaly use it when ssh_is_server_known() answered SSH_SERVER_NOT_KNOWN.
write the current server as known in the known hosts file. This will create the known hosts file if it does not exist.
session | ssh session |
References ssh_dirname(), ssh_mkdir(), ssh_options_set(), and string_len().