libssh
0.5.4
|
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_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_issue_banner (ssh_session session) |
Get the issue banner from the server. 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_pubkey_hash (ssh_session session, unsigned char **hash) |
Allocates a buffer with the MD5 hash of the server public key. 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_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... | |
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... | |
void | ssh_set_blocking (ssh_session session, int blocking) |
Set the session in blocking/nonblocking mode. 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(), SSH_LOG_PACKET, SSH_LOG_PROTOCOL, and SSH_LOG_RARE.
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_channel_free(), ssh_string_free(), and ssh_string_from_char().
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 privatekey_free(), ssh_buffer_free(), ssh_channel_free(), and ssh_poll_ctx_free().
Referenced by ssh_new().
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_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().
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().
int ssh_get_pubkey_hash | ( | ssh_session | session, |
unsigned char ** | hash | ||
) |
Allocates a buffer with the MD5 hash of the server public key.
[in] | session | The SSH session to use. |
[in] | hash | The buffer to allocate. |
References ssh_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. |
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_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_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().
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. |
Referenced by ssh::Session::optionsCopy().
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().
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_options_set(), and ssh_path_expand_tilde().
Referenced by ssh::Session::setOption(), ssh_options_getopt(), ssh_options_parse_config(), and ssh_options_set().
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 | A timeout for the select. |
References ssh_channel_poll().
void ssh_set_blocking | ( | ssh_session | session, |
int | blocking | ||
) |
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_mkdir(), and ssh_string_len().
Referenced by ssh_is_server_known(), and ssh::Session::writeKnownhost().