libssh
0.7
|
Functions that manage a session. More...
Functions | |
int | ssh_blocking_flush (ssh_session session, int timeout) |
Blocking flush of the outgoing buffer. More... | |
void | ssh_clean_pubkey_hash (unsigned char **hash) |
Deallocate the hash obtained by ssh_get_pubkey_hash. More... | |
int | ssh_connect (ssh_session session) |
Connect to the ssh server. More... | |
void | ssh_disconnect (ssh_session session) |
Disconnect from a session (client or server). More... | |
void | ssh_free (ssh_session session) |
Deallocate a SSH session handle. More... | |
const char * | ssh_get_cipher_in (ssh_session session) |
get the name of the input cipher for the given session. More... | |
const char * | ssh_get_cipher_out (ssh_session session) |
get the name of the output cipher for the given session. More... | |
const char * | ssh_get_clientbanner (ssh_session session) |
get the client banner More... | |
const char * | ssh_get_disconnect_message (ssh_session session) |
Get the disconnect message from the server. More... | |
socket_t | ssh_get_fd (ssh_session session) |
Get the fd of a connection. More... | |
char * | ssh_get_hexa (const unsigned char *what, size_t len) |
Convert a buffer into a colon separated hex string. More... | |
const char * | ssh_get_hmac_in (ssh_session session) |
get the name of the input HMAC algorithm for the given session. More... | |
const char * | ssh_get_hmac_out (ssh_session session) |
get the name of the output HMAC algorithm for the given session. More... | |
char * | ssh_get_issue_banner (ssh_session session) |
Get the issue banner from the server. More... | |
const char * | ssh_get_kex_algo (ssh_session session) |
get the name of the current key exchange algorithm. More... | |
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. More... | |
int | ssh_get_poll_flags (ssh_session session) |
Get poll flags for an external mainloop. More... | |
int | ssh_get_pubkey_hash (ssh_session session, unsigned char **hash) |
int | ssh_get_publickey (ssh_session session, ssh_key *key) |
Get the server public key from a session. More... | |
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. More... | |
const char * | ssh_get_serverbanner (ssh_session session) |
get the server banner More... | |
int | ssh_get_status (ssh_session session) |
Get session status. More... | |
int | ssh_get_version (ssh_session session) |
Get the protocol version of the session. More... | |
int | ssh_is_blocking (ssh_session session) |
Return the blocking mode of libssh. More... | |
int | ssh_is_connected (ssh_session session) |
Check if we are connected. More... | |
int | ssh_is_server_known (ssh_session session) |
Check if the server is known. More... | |
ssh_session | ssh_new (void) |
Create a new ssh session. More... | |
int | ssh_options_copy (ssh_session src, ssh_session *dest) |
Duplicate the options of a session structure. More... | |
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, but mostly those which a user-space program may care about having trusted the ssh driver to infer these values from underlaying configuration files. More... | |
int | ssh_options_get_port (ssh_session session, unsigned int *port_target) |
This function can get ssh the ssh port. More... | |
int | ssh_options_getopt (ssh_session session, int *argcptr, char **argv) |
Parse command line arguments. More... | |
int | ssh_options_parse_config (ssh_session session, const char *filename) |
Parse the ssh config file. More... | |
int | ssh_options_set (ssh_session session, enum ssh_options_e type, const void *value) |
This function can set all possible ssh options. More... | |
void | ssh_print_hexa (const char *descr, const unsigned char *what, size_t len) |
Print a buffer as colon separated hex string. More... | |
int | ssh_select (ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout) |
A wrapper for the select syscall. More... | |
int | ssh_send_debug (ssh_session session, const char *message, int always_display) |
Send a debug message. More... | |
int | ssh_send_ignore (ssh_session session, const char *data) |
Send a message that should be ignored. More... | |
void | ssh_set_blocking (ssh_session session, int blocking) |
Set the session in blocking/nonblocking mode. More... | |
void | ssh_set_counters (ssh_session session, ssh_counter scounter, ssh_counter rcounter) |
Set the session data counters. More... | |
void | ssh_set_fd_except (ssh_session session) |
Tell the session it has an exception to catch on the file descriptor. More... | |
void | ssh_set_fd_toread (ssh_session session) |
Tell the session it has data to read on the file descriptor without blocking. More... | |
void | ssh_set_fd_towrite (ssh_session session) |
Tell the session it may write to the file descriptor without blocking. More... | |
void | ssh_silent_disconnect (ssh_session session) |
Disconnect impolitely from a remote host by closing the socket. More... | |
int | ssh_write_knownhost (ssh_session session) |
Write the current server as known in the known hosts file. More... | |
Functions that manage a session.
int ssh_blocking_flush | ( | ssh_session | session, |
int | timeout | ||
) |
Blocking flush of the outgoing buffer.
[in] | session | The SSH session |
[in] | timeout | Set an upper limit on the time for which this function will block, in milliseconds. Specifying -1 means an infinite timeout. This parameter is passed to the poll() function. |
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.
[in] | hash | The buffer to deallocate. |
int ssh_connect | ( | ssh_session | session | ) |
Connect to the ssh server.
[in] | session | The ssh session to connect. |
References ssh_init(), ssh_is_blocking(), SSH_LOG_PACKET, and SSH_LOG_PROTOCOL.
Referenced by ssh::Session::connect().
void ssh_disconnect | ( | ssh_session | session | ) |
Disconnect from a session (client or server).
The session can then be reused to open a new session.
[in] | session | The SSH session to use. |
References ssh_message_free().
Referenced by ssh::Session::disconnect(), and ssh_silent_disconnect().
void ssh_free | ( | ssh_session | session | ) |
Deallocate a SSH session handle.
[in] | session | The SSH session to free. |
References ssh_buffer_free(), ssh_key_free(), ssh_message_free(), and ssh_poll_ctx_free().
Referenced by ssh_new(), and ssh_options_copy().
const char* ssh_get_cipher_in | ( | ssh_session | session | ) |
get the name of the input cipher for the given session.
[in] | session | The SSH session. |
const char* ssh_get_cipher_out | ( | ssh_session | session | ) |
get the name of the output cipher for the given session.
[in] | session | The SSH session. |
const char* ssh_get_clientbanner | ( | ssh_session | session | ) |
get the client banner
[in] | session | The SSH session |
const char* ssh_get_disconnect_message | ( | ssh_session | session | ) |
Get the disconnect message from the server.
[in] | session | The ssh session to use. |
Referenced by ssh::Session::getDisconnectMessage().
socket_t ssh_get_fd | ( | ssh_session | session | ) |
Get the fd of a connection.
In case you'd need the file descriptor of the connection to the server/client.
[in] | session | The ssh session to use. |
Referenced by ssh::Session::getSocket().
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.
what | What should be converted to a hex string. |
len | Length of the buffer to convert. |
Referenced by ssh_print_hexa().
const char* ssh_get_hmac_in | ( | ssh_session | session | ) |
get the name of the input HMAC algorithm for the given session.
[in] | session | The SSH session. |
const char* ssh_get_hmac_out | ( | ssh_session | session | ) |
get the name of the output HMAC algorithm for the given session.
[in] | session | The 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.
[in] | session | The SSH session to use. |
References ssh_string_to_char().
Referenced by ssh::Session::getIssueBanner().
const char* ssh_get_kex_algo | ( | ssh_session | session | ) |
get the name of the current key exchange algorithm.
[in] | session | The SSH session |
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.
[in] | session | The SSH session to use. |
Referenced by ssh::Session::getOpensshVersion(), and sftp_symlink().
int ssh_get_poll_flags | ( | ssh_session | session | ) |
Get poll flags for an external mainloop.
session | The ssh session to use. |
int ssh_get_pubkey_hash | ( | ssh_session | session, |
unsigned char ** | hash | ||
) |
References ssh_string_data(), and ssh_string_len().
int ssh_get_publickey | ( | ssh_session | session, |
ssh_key * | key | ||
) |
Get the server public key from a session.
[in] | session | The session to get the key from. |
[out] | key | A pointer to store the allocated key. You need to free the key. |
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.
This function allows you to get a hash of the public key. You can then print this hash in a human-readable form to the user so that he is able to verify it. Use ssh_get_hexa() or ssh_print_hexa() to display it.
[in] | key | The public key to create the hash for. |
[in] | type | The type of the hash you want. |
[in] | hash | A pointer to store the allocated buffer. It can be freed using ssh_clean_pubkey_hash(). |
[in] | hlen | The length of the hash. |
References ssh_string_data(), ssh_string_free(), and ssh_string_len().
const char* ssh_get_serverbanner | ( | ssh_session | session | ) |
get the server banner
[in] | session | The SSH session |
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. |
Referenced by ssh::Session::getVersion().
int ssh_is_blocking | ( | ssh_session | session | ) |
Return the blocking mode of libssh.
[in] | session | The SSH session |
Referenced by ssh_channel_read_nonblocking(), and ssh_connect().
int ssh_is_connected | ( | ssh_session | session | ) |
Check if we are connected.
[in] | session | The session to check if it is connected. |
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.
[in] | session | The SSH session to use. |
References SSH_LOG_PACKET, and ssh_write_knownhost().
Referenced by ssh::Session::isServerKnown().
ssh_session ssh_new | ( | void | ) |
Create a new ssh session.
References ssh_buffer_new(), ssh_free(), and ssh_set_blocking().
Referenced by ssh_options_copy().
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 | A pointer to store the allocated session with duplicated options. You have to free the memory. |
References ssh_free(), and ssh_new().
Referenced by ssh::Session::optionsCopy().
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, but mostly those which a user-space program may care about having trusted the ssh driver to infer these values from underlaying configuration files.
It operates only on those SSH_OPTIONS_* which return char*. If you wish to receive the port then please use ssh_options_get_port() which returns an unsigned int.
session | An allocated SSH session structure. |
type | The option type to get. This could be one of the following: |
value | The value to get into. As a char**, space will be allocated by the function for the value, it is your responsibility to free the memory using ssh_string_free_char(). |
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. This function is useful when the session options have been automatically inferred from the environment or configuration files and one
session | An allocated SSH session structure. |
port_target | An unsigned integer into which the port will be set from the ssh session. |
int ssh_options_getopt | ( | ssh_session | session, |
int * | argcptr, | ||
char ** | argv | ||
) |
Parse command line arguments.
This is a helper for your application to generate the appropriate options from the command line arguments.
The argv array and argc value are changed so that the parsed arguments wont appear anymore in them.
The single arguments (without switches) are not parsed. thus, myssh -l user localhost
The command wont set the hostname value of options to localhost.
session | The session to configure. |
argcptr | The pointer to the argument count. |
argv | The arguments list pointer. |
References ssh_options_set(), and ssh_set_log_level().
int ssh_options_parse_config | ( | ssh_session | session, |
const char * | filename | ||
) |
Parse the ssh config file.
This should be the last call of all options, it may overwrite options which are already set. It requires that the host name is already set with ssh_options_set_host().
session | SSH session handle |
filename | The options file to use, if NULL the default ~/.ssh/config will be used. |
References ssh_options_set().
Referenced by ssh::Session::optionsParseConfig().
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 session structure. |
type | The option type to set. This could be one of the following: |
value | The value to set. This is a generic pointer and the datatype which is used should be set according to the type set. |
References ssh_path_expand_tilde(), and ssh_set_log_level().
Referenced by ssh::Session::setOption(), ssh_options_getopt(), and ssh_options_parse_config().
void ssh_print_hexa | ( | const char * | descr, |
const unsigned char * | what, | ||
size_t | len | ||
) |
Print a buffer as colon separated hex string.
descr | Description printed in front of the hex string. |
what | What should be converted to a hex string. |
len | Length of the buffer to convert. |
References ssh_get_hexa().
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.
[in] | channels | Arrays of channels pointers terminated by a NULL. It is never rewritten. |
[out] | outchannels | Arrays of same size that "channels", there is no need to initialize it. |
[in] | maxfd | Maximum +1 file descriptor from readfds. |
[in] | readfds | A fd_set of file descriptors to be select'ed for reading. |
[in] | timeout | The timeout in milliseconds. |
References ssh_channel_poll(), ssh_event_add_fd(), ssh_event_add_session(), ssh_event_dopoll(), ssh_event_free(), ssh_event_new(), ssh_event_remove_fd(), and ssh_timeout_update().
int ssh_send_debug | ( | ssh_session | session, |
const char * | message, | ||
int | always_display | ||
) |
Send a debug message.
[in] | session | The SSH session |
[in] | message | Data to be sent |
[in] | always_display | Message SHOULD be displayed by the server. It SHOULD NOT be displayed unless debugging information has been explicitly requested. |
int ssh_send_ignore | ( | ssh_session | session, |
const char * | data | ||
) |
Send a message that should be ignored.
[in] | session | The SSH session |
[in] | data | Data to be sent |
void ssh_set_blocking | ( | ssh_session | session, |
int | blocking | ||
) |
Set the session in blocking/nonblocking mode.
[in] | session | The ssh session to change. |
[in] | blocking | Zero for nonblocking mode. |
Referenced by ssh_channel_read_nonblocking(), ssh_channel_set_blocking(), and ssh_new().
void ssh_set_counters | ( | ssh_session | session, |
ssh_counter | scounter, | ||
ssh_counter | rcounter | ||
) |
Set the session data counters.
This functions sets the counter structures to be used to calculate data which comes in and goes out through the session at different levels.
[in] | session | The SSH session. |
[in] | scounter | Counter for byte data handled by the session sockets. |
[in] | rcounter | Counter for byte and packet data handled by the session, prior compression and SSH overhead. |
void ssh_set_fd_except | ( | ssh_session | session | ) |
Tell the session it has an exception to catch on the file descriptor.
[in] | session | The ssh session to use. |
void ssh_set_fd_toread | ( | ssh_session | session | ) |
Tell the session it has data to read on the file descriptor without blocking.
[in] | session | The ssh session to use. |
void ssh_set_fd_towrite | ( | ssh_session | session | ) |
Tell the session it may write to the file descriptor without blocking.
[in] | session | The ssh session to use. |
void ssh_silent_disconnect | ( | ssh_session | session | ) |
Disconnect impolitely from a remote host by closing the socket.
Suitable if you forked and want to destroy this session.
[in] | session | The SSH session to disconnect. |
References ssh_disconnect().
Referenced by ssh::Session::silentDisconnect().
int ssh_write_knownhost | ( | ssh_session | session | ) |
Write the current server as known in the known hosts file.
This will create the known hosts file if it does not exist. You generaly use it when ssh_is_server_known() answered SSH_SERVER_NOT_KNOWN.
[in] | session | The ssh session to use. |
References ssh_dirname(), ssh_key_free(), ssh_mkdir(), and ssh_pki_export_pubkey_base64().
Referenced by ssh_is_server_known(), and ssh::Session::writeKnownhost().