class ssh::Session

Overview

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

#include <include/libssh/libsshpp.hpp>

class Session {
public:
    // construction

    ~Session();

    // methods

    Channel*
    acceptForward(int timeout_ms);

    void
    cancelForward(
        const char* address,
        int port
    );

    void
    connect();

    void
    disconnect();

    int
    getAuthList();

    const char*
    getDisconnectMessage();

    const char*
    getError();

    int
    getErrorCode();

    std::string
    getIssueBanner();

    int
    getOpensshVersion();

    socket_t
    getSocket();

    int
    getVersion();

    int
    isServerKnown();

    void
    listenForward(
        const char* address,
        int port,
        int& boundport
    );

    void
    log(
        int priority,
        const char* format,
        ...
    );

    void
    optionsCopy(const Session& source);

    void
    optionsParseConfig(const char* file);

    void
    setOption(
        enum ssh_options_e type,
        const char* option
    );

    void
    setOption(
        enum ssh_options_e type,
        long int option
    );

    void
    setOption(
        enum ssh_options_e type,
        void* option
    );

    void
    silentDisconnect();

    int
    userauthNone();

    int
    userauthPassword(const char* password);

    int
    userauthPrivatekeyFile(
        const char* filename,
        const char* passphrase
    );

    int
    userauthPublickey(ssh_key privkey);

    int
    userauthPublickeyAuto(void);

    int
    userauthTryPublickey(ssh_key pubkey);

    int
    writeKnownhost();
};

Detailed Documentation

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

Methods

Channel*
acceptForward(int timeout_ms)

accept an incoming forward connection

Warning

you have to delete this pointer after use

Parameters:

timeout_ms

timeout for waiting, in ms

Returns:

new Channel pointer on the forward connection

NULL in case of error

See also:

ssh_channel_forward_accept

Session::listenForward

void
connect()

connects to the remote host

Parameters:

SshException

on error

See also:

ssh_connect

void
disconnect()

Disconnects from the SSH server and closes connection.

See also:

ssh_disconnect

int
getAuthList()

Returns the available authentication methods from the server.

Parameters:

SshException

on error

Returns:

Bitfield of available methods.

See also:

ssh_userauth_list

const char*
getDisconnectMessage()

Returns the disconnect message from the server, if any.

Returns:

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

std::string
getIssueBanner()

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

int
getOpensshVersion()

returns the OpenSSH version (server) if possible

Returns:

openssh version code

See also:

ssh_get_openssh_version

socket_t
getSocket()

returns the file descriptor used for the communication

Warning

if a proxycommand is used, this function will only return one of the two file descriptors being used

Returns:

the file descriptor

See also:

ssh_get_fd

int
getVersion()

returns the version of the SSH protocol being used

Returns:

the SSH protocol version

See also:

ssh_get_version

int
isServerKnown()

verifies that the server is known

Parameters:

SshException

on error

Returns:

Integer value depending on the knowledge of the server key

See also:

ssh_is_server_known

void
optionsCopy(const Session& source)

copies options from a session to another

Parameters:

SshException

on error

See also:

ssh_options_copy

void
optionsParseConfig(const char* file)

parses a configuration file for options

Parameters:

SshException

on error

file

configuration file name

See also:

ssh_options_parse_config

void
setOption(
    enum ssh_options_e type,
    const char* option
)

sets an SSH session options

Parameters:

type

Type of option

option

cstring containing the value of option

SshException

on error

See also:

ssh_options_set

void
setOption(
    enum ssh_options_e type,
    long int option
)

sets an SSH session options

Parameters:

type

Type of option

option

long integer containing the value of option

SshException

on error

See also:

ssh_options_set

void
setOption(
    enum ssh_options_e type,
    void* option
)

sets an SSH session options

Parameters:

type

Type of option

option

void pointer containing the value of option

SshException

on error

See also:

ssh_options_set

void
silentDisconnect()

silently disconnect from remote host

See also:

ssh_silent_disconnect

int
userauthNone()

Authenticates using the “none” method.

Prefer using autopubkey if possible.

Parameters:

SshException

on error

Returns:

SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED

See also:

ssh_userauth_none

Session::userauthAutoPubkey

int
userauthPassword(const char* password)

Authenticates using the password method.

Parameters:

password

password to use for authentication

SshException

on error

Returns:

SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED

See also:

ssh_userauth_password

int
userauthPublickey(ssh_key privkey)

Authenticates using the publickey method.

Parameters:

privkey

private key to use for authentication

SshException

on error

Returns:

SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED

See also:

ssh_userauth_pubkey

int
userauthPublickeyAuto(void)

Authenticates automatically using public key.

Parameters:

SshException

on error

Returns:

SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED

See also:

ssh_userauth_autopubkey

int
userauthTryPublickey(ssh_key pubkey)

Try to authenticate using the publickey method.

Parameters:

pubkey

public key to use for authentication

SshException

on error

Returns:

SSH_AUTH_SUCCESS if the pubkey is accepted,

SSH_AUTH_DENIED if the pubkey is denied

See also:

ssh_userauth_try_pubkey

int
writeKnownhost()

Writes the known host file with current host key.

Parameters:

SshException

on error

See also:

ssh_write_knownhost