libssh  0.10.90
The SSH library
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Friends
ssh::Session Class Reference

#include <libsshpp.hpp>

Collaboration diagram for ssh::Session:
Collaboration graph
[legend]

Public Member Functions

void_throwable setOption (enum ssh_options_e type, const char *option)
 sets an SSH session options
 
void_throwable setOption (enum ssh_options_e type, long int option)
 sets an SSH session options
 
void_throwable setOption (enum ssh_options_e type, void *option)
 sets an SSH session options
 
void_throwable connect ()
 connects to the remote host
 
int userauthPublickeyAuto (void)
 Authenticates automatically using public key.
 
int userauthNone ()
 Authenticates using the "none" method. Prefer using autopubkey if possible.
 
int userauthKbdint (const char *username, const char *submethods)
 Authenticate through the "keyboard-interactive" method.
 
int userauthKbdintGetNPrompts ()
 Get the number of prompts (questions) the server has given.
 
int userauthKbdintSetAnswer (unsigned int index, const char *answer)
 Set the answer for a question from a message block.
 
int userauthPassword (const char *password)
 Authenticates using the password method.
 
int userauthTryPublickey (ssh_key pubkey)
 Try to authenticate using the publickey method.
 
int userauthPublickey (ssh_key privkey)
 Authenticates using the publickey method.
 
int getAuthList ()
 Returns the available authentication methods from the server.
 
void disconnect ()
 Disconnects from the SSH server and closes connection.
 
const char * getDisconnectMessage ()
 Returns the disconnect message from the server, if any.
 
const char * getError ()
 
int getErrorCode ()
 
socket_t getSocket ()
 returns the file descriptor used for the communication
 
std::string getIssueBanner ()
 gets the Issue banner from the ssh server
 
int getOpensshVersion ()
 returns the OpenSSH version (server) if possible
 
int getVersion ()
 returns the version of the SSH protocol being used
 
int isServerKnown ()
 verifies that the server is known
 
void log (int priority, const char *format,...)
 
void_throwable optionsCopy (const Session &source)
 copies options from a session to another
 
void_throwable optionsParseConfig (const char *file)
 parses a configuration file for options
 
void silentDisconnect ()
 silently disconnect from remote host
 
int writeKnownhost ()
 Writes the known host file with current host key.
 
ChannelacceptForward (int timeout_ms)
 accept an incoming forward connection
 
void_throwable cancelForward (const char *address, int port)
 
void_throwable listenForward (const char *address, int port, int &boundport)
 
ssh_session getCSession ()
 

Protected Attributes

ssh_session c_session
 

Friends

class Channel
 

Detailed Description

The ssh::Session class contains the state of a SSH connection.

Member Function Documentation

◆ acceptForward()

Channel * ssh::Session::acceptForward ( int timeout_ms)
inline

accept an incoming forward connection

Parameters
[in]timeout_mstimeout for waiting, in ms
Returns
new Channel pointer on the forward connection
NULL in case of error
Warning
you have to delete this pointer after use
See also
ssh_channel_forward_accept
Session::listenForward

◆ connect()

void_throwable ssh::Session::connect ( )
inline

connects to the remote host

Exceptions
SshExceptionon error
See also
ssh_connect

◆ disconnect()

void ssh::Session::disconnect ( )
inline

Disconnects from the SSH server and closes connection.

See also
ssh_disconnect

◆ getAuthList()

int ssh::Session::getAuthList ( )
inline

Returns the available authentication methods from the server.

Exceptions
SshExceptionon error
Returns
Bitfield of available methods.
See also
ssh_userauth_list

◆ getDisconnectMessage()

const char * ssh::Session::getDisconnectMessage ( )
inline

Returns the disconnect message from the server, if any.

Returns
pointer to the message, or NULL. Do not attempt to free the pointer.

◆ getIssueBanner()

std::string ssh::Session::getIssueBanner ( )
inline

gets the Issue banner from the ssh server

Returns
the issue banner. This is generally a MOTD from server
See also
ssh_get_issue_banner

◆ getOpensshVersion()

int ssh::Session::getOpensshVersion ( )
inline

returns the OpenSSH version (server) if possible

Returns
openssh version code
See also
ssh_get_openssh_version

◆ getSocket()

socket_t ssh::Session::getSocket ( )
inline

returns the file descriptor used for the communication

Returns
the file descriptor
Warning
if a proxycommand is used, this function will only return one of the two file descriptors being used
See also
ssh_get_fd

◆ getVersion()

int ssh::Session::getVersion ( )
inline

returns the version of the SSH protocol being used

Returns
the SSH protocol version
See also
ssh_get_version

◆ isServerKnown()

int ssh::Session::isServerKnown ( )
inline

verifies that the server is known

Exceptions
SshExceptionon error
Returns
Integer value depending on the knowledge of the server key
See also
ssh_session_update_known_hosts

◆ optionsCopy()

void_throwable ssh::Session::optionsCopy ( const Session & source)
inline

copies options from a session to another

Exceptions
SshExceptionon error
See also
ssh_options_copy

◆ optionsParseConfig()

void_throwable ssh::Session::optionsParseConfig ( const char * file)
inline

parses a configuration file for options

Exceptions
SshExceptionon error
Parameters
[in]fileconfiguration file name
See also
ssh_options_parse_config

◆ setOption() [1/3]

void_throwable ssh::Session::setOption ( enum ssh_options_e type,
const char * option )
inline

sets an SSH session options

Parameters
typeType of option
optioncstring containing the value of option
Exceptions
SshExceptionon error
See also
ssh_options_set

◆ setOption() [2/3]

void_throwable ssh::Session::setOption ( enum ssh_options_e type,
long int option )
inline

sets an SSH session options

Parameters
typeType of option
optionlong integer containing the value of option
Exceptions
SshExceptionon error
See also
ssh_options_set

◆ setOption() [3/3]

void_throwable ssh::Session::setOption ( enum ssh_options_e type,
void * option )
inline

sets an SSH session options

Parameters
typeType of option
optionvoid pointer containing the value of option
Exceptions
SshExceptionon error
See also
ssh_options_set

◆ silentDisconnect()

void ssh::Session::silentDisconnect ( )
inline

silently disconnect from remote host

See also
ssh_silent_disconnect

◆ userauthKbdint()

int ssh::Session::userauthKbdint ( const char * username,
const char * submethods )
inline

Authenticate through the "keyboard-interactive" method.

Parameters
[in]usernameThe username to authenticate. You can specify NULL if ssh_option_set_username() has been used. You cannot try two different logins in a row.
[in]submethodsUndocumented. Set it to NULL.
Exceptions
SshExceptionon error
Returns
SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED, SSH_AUTH_ERROR, SSH_AUTH_INFO, SSH_AUTH_AGAIN
See also
ssh_userauth_kbdint

◆ userauthKbdintGetNPrompts()

int ssh::Session::userauthKbdintGetNPrompts ( )
inline

Get the number of prompts (questions) the server has given.

Returns
The number of prompts.
See also
ssh_userauth_kbdint_getnprompts

◆ userauthKbdintSetAnswer()

int ssh::Session::userauthKbdintSetAnswer ( unsigned int index,
const char * answer )
inline

Set the answer for a question from a message block.

Parameters
[in]indexThe index number of the prompt.
[in]answerThe answer to give to the server. The answer MUST be encoded UTF-8. It is up to the server how to interpret the value and validate it. However, if you read the answer in some other encoding, you MUST convert it to UTF-8.
Exceptions
SshExceptionon error
Returns
0 on success, < 0 on error
See also
ssh_userauth_kbdint_setanswer

◆ userauthNone()

int ssh::Session::userauthNone ( )
inline

Authenticates using the "none" method. Prefer using autopubkey if possible.

Exceptions
SshExceptionon error
Returns
SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
See also
ssh_userauth_none
Session::userauthAutoPubkey

◆ userauthPassword()

int ssh::Session::userauthPassword ( const char * password)
inline

Authenticates using the password method.

Parameters
[in]passwordpassword to use for authentication
Exceptions
SshExceptionon error
Returns
SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
See also
ssh_userauth_password

◆ userauthPublickey()

int ssh::Session::userauthPublickey ( ssh_key privkey)
inline

Authenticates using the publickey method.

Parameters
[in]privkeyprivate key to use for authentication
Exceptions
SshExceptionon error
Returns
SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
See also
ssh_userauth_pubkey

◆ userauthPublickeyAuto()

int ssh::Session::userauthPublickeyAuto ( void )
inline

Authenticates automatically using public key.

Exceptions
SshExceptionon error
Returns
SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
See also
ssh_userauth_autopubkey

◆ userauthTryPublickey()

int ssh::Session::userauthTryPublickey ( ssh_key pubkey)
inline

Try to authenticate using the publickey method.

Parameters
[in]pubkeypublic key to use for authentication
Exceptions
SshExceptionon error
Returns
SSH_AUTH_SUCCESS if the pubkey is accepted,
SSH_AUTH_DENIED if the pubkey is denied
See also
ssh_userauth_try_pubkey

◆ writeKnownhost()

int ssh::Session::writeKnownhost ( )
inline

Writes the known host file with current host key.

Exceptions
SshExceptionon error
See also
ssh_write_knownhost

The documentation for this class was generated from the following file: