libssh 0.12.0
The SSH library
Loading...
Searching...
No Matches
libsshpp.hpp
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2010 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef LIBSSHPP_HPP_
22#define LIBSSHPP_HPP_
23
50
51/* do not use deprecated functions */
52#define LIBSSH_LEGACY_0_4
53
54#include <libssh/libssh.h>
55#include <libssh/server.h>
56#include <stdlib.h>
57#include <stdarg.h>
58#include <stdio.h>
59#include <string>
60
61namespace ssh {
62
63class Channel;
68#ifndef SSH_NO_CPP_EXCEPTIONS
69
75 public:
85 SshException(ssh_session csession)
86 {
87 code = ssh_get_error_code(csession);
88 description = std::string(ssh_get_error(csession));
89 }
90
95 {
96 code = e.code;
97 description = e.description;
98 }
99
107 {
108 return code;
109 }
110
116 std::string getError()
117 {
118 return description;
119 }
120
121 private:
122 int code;
123 std::string description;
124};
125
129#define ssh_throw(x) if((x)==SSH_ERROR) throw SshException(getCSession())
130#define ssh_throw_null(CSession,x) if((x)==NULL) throw SshException(CSession)
131#define void_throwable void
132#define return_throwable return
133
134#else
135
136/* No exception at all. All functions will return an error code instead
137 * of an exception
138 */
139#define ssh_throw(x) if((x)==SSH_ERROR) return SSH_ERROR
140#define ssh_throw_null(CSession,x) if((x)==NULL) return NULL
141#define void_throwable int
142#define return_throwable return SSH_OK
143#endif
144
148class Session {
149 friend class Channel;
150public:
151 Session(){
152 c_session=ssh_new();
153 }
154 ~Session(){
155 ssh_free(c_session);
156 c_session=NULL;
157 }
167 void_throwable setOption(enum ssh_options_e type, const char *option){
168 ssh_throw(ssh_options_set(c_session,type,option));
169 return_throwable;
170 }
171
180 void_throwable setOption(enum ssh_options_e type, long int option){
181 ssh_throw(ssh_options_set(c_session,type,&option));
182 return_throwable;
183 }
184
193 void_throwable setOption(enum ssh_options_e type, void *option){
194 ssh_throw(ssh_options_set(c_session,type,option));
195 return_throwable;
196 }
197
203 void_throwable connect(){
204 int ret=ssh_connect(c_session);
205 ssh_throw(ret);
206 return_throwable;
207 }
208
217 int ret=ssh_userauth_publickey_auto(c_session, NULL, NULL);
218 ssh_throw(ret);
219 return ret;
220 }
221
233 int ret=ssh_userauth_none(c_session,NULL);
234 ssh_throw(ret);
235 return ret;
236 }
237
254 int userauthKbdint(const char* username, const char* submethods){
255 int ret = ssh_userauth_kbdint(c_session, username, submethods);
256 ssh_throw(ret);
257 return ret;
258 }
259
268
284 int userauthKbdintSetAnswer(unsigned int index, const char *answer)
285 {
286 int ret = ssh_userauth_kbdint_setanswer(c_session, index, answer);
287 ssh_throw(ret);
288 return ret;
289 }
290
300 int userauthPassword(const char *password){
301 int ret=ssh_userauth_password(c_session,NULL,password);
302 ssh_throw(ret);
303 return ret;
304 }
305
316 int userauthTryPublickey(ssh_key pubkey){
317 int ret=ssh_userauth_try_publickey(c_session, NULL, pubkey);
318 ssh_throw(ret);
319 return ret;
320 }
321
330 int userauthPublickey(ssh_key privkey){
331 int ret=ssh_userauth_publickey(c_session, NULL, privkey);
332 ssh_throw(ret);
333 return ret;
334 }
335
344 int ret=ssh_userauth_list(c_session, NULL);
345 ssh_throw(ret);
346 return ret;
347 }
348
352 ssh_disconnect(c_session);
353 }
354
359 const char *getDisconnectMessage(){
360 const char *msg=ssh_get_disconnect_message(c_session);
361 return msg;
362 }
363
366 const char *getError()
367 {
368 return ssh_get_error(c_session);
369 }
373 int getErrorCode()
374 {
375 return ssh_get_error_code(c_session);
376 }
385 socket_t getSocket(){
386 return ssh_get_fd(c_session);
387 }
388
393 std::string getIssueBanner(){
394 char *banner = ssh_get_issue_banner(c_session);
395 std::string ret = "";
396 if (banner != NULL) {
397 ret = std::string(banner);
398 ::free(banner);
399 }
400 return ret;
401 }
402
408 return ssh_get_openssh_version(c_session);
409 }
410
416 return ssh_get_version(c_session);
417 }
418
426 int state = ssh_session_is_known_server(c_session);
427 ssh_throw(state);
428 return state;
429 }
430 void log(int priority, const char *format, ...){
431 va_list va;
432
433 va_start(va, format);
434 ssh_vlog(priority, "libsshpp", format, &va);
435 va_end(va);
436 }
437
443 void_throwable optionsCopy(const Session &source){
444 ssh_throw(ssh_options_copy(source.c_session,&c_session));
445 return_throwable;
446 }
447
455 void_throwable optionsParseConfig(const char *file){
456 ssh_throw(ssh_options_parse_config(c_session,file));
457 return_throwable;
458 }
459
463 ssh_silent_disconnect(c_session);
464 }
465
471 int ret = ssh_session_update_known_hosts(c_session);
472 ssh_throw(ret);
473 return ret;
474 }
475
488 inline Channel *acceptForward(int timeout_ms);
489 /* implemented outside the class due Channel references */
490
491 void_throwable cancelForward(const char *address, int port){
492 int err=ssh_channel_cancel_forward(c_session, address, port);
493 ssh_throw(err);
494 return_throwable;
495 }
496
497 void_throwable listenForward(const char *address, int port,
498 int &boundport){
499 int err=ssh_channel_listen_forward(c_session, address, port, &boundport);
500 ssh_throw(err);
501 return_throwable;
502 }
503
504 ssh_session getCSession(){
505 return c_session;
506 }
507
508protected:
512 ssh_session c_session;
513
514private:
515 /* No copy constructor, no = operator */
516 Session(const Session &);
517 Session& operator=(const Session &);
518};
519
523class Channel {
524 friend class Session;
525public:
526 Channel(Session &ssh_session){
527 channel = ssh_channel_new(ssh_session.getCSession());
528 this->session = &ssh_session;
529 }
530 ~Channel(){
531 ssh_channel_free(channel);
532 channel=NULL;
533 }
534
547 Channel *acceptX11(int timeout_ms){
548 ssh_channel x11chan = ssh_channel_accept_x11(channel,timeout_ms);
549 ssh_throw_null(getCSession(),x11chan);
550 Channel *newchan = new Channel(getSession(),x11chan);
551 return newchan;
552 }
553
561 void_throwable changePtySize(int cols, int rows){
562 int err=ssh_channel_change_pty_size(channel,cols,rows);
563 ssh_throw(err);
564 return_throwable;
565 }
566
572 void_throwable close(){
573 ssh_throw(ssh_channel_close(channel));
574 return_throwable;
575 }
576
577 /*
578 * @deprecated Please use getExitState()
579 */
580 int getExitStatus() {
581 uint32_t exit_status = (uint32_t)-1;
582 ssh_channel_get_exit_state(channel, &exit_status, NULL, NULL);
583 return exit_status;
584 }
585 void_throwable getExitState(uint32_t & pexit_code,
586 char **pexit_signal,
587 int & pcore_dumped) {
588 ssh_throw(ssh_channel_get_exit_state(channel,
589 &pexit_code,
590 pexit_signal,
591 &pcore_dumped));
592 return_throwable;
593 }
594 Session &getSession(){
595 return *session;
596 }
600 bool isClosed(){
601 return ssh_channel_is_closed(channel) != 0;
602 }
603
606 bool isEof(){
607 return ssh_channel_is_eof(channel) != 0;
608 }
609
612 bool isOpen(){
613 return ssh_channel_is_open(channel) != 0;
614 }
615
630 int openForward(const char *remotehost, int remoteport,
631 const char *sourcehost, int localport=0){
632 int err=ssh_channel_open_forward(channel,remotehost,remoteport,
633 sourcehost, localport);
634 ssh_throw(err);
635 return err;
636 }
637 /* TODO: completely remove this ? */
638 void_throwable openSession(){
639 int err=ssh_channel_open_session(channel);
640 ssh_throw(err);
641 return_throwable;
642 }
653 int poll(bool is_stderr = false)
654 {
655 int err = ssh_channel_poll(channel, is_stderr);
656 ssh_throw(err);
657 return err;
658 }
659
670 int read(void *dest, size_t count)
671 {
672 int err;
673 if (count > 0x7fffffff)
674 count = 0x7fffffff;
675 err = ssh_channel_read_timeout(channel, dest, count, false, -1);
676 ssh_throw(err);
677 return err;
678 }
679
692 int read(void *dest, size_t count, int timeout){
693 int err;
694 /* handle int overflow */
695 if(count > 0x7fffffff)
696 count = 0x7fffffff;
697 err=ssh_channel_read_timeout(channel,dest,count,false,timeout);
698 ssh_throw(err);
699 return err;
700 }
701
717 int read(void *dest, size_t count, bool is_stderr=false, int timeout=-1){
718 int err;
719 /* handle int overflow */
720 if(count > 0x7fffffff)
721 count = 0x7fffffff;
722 err=ssh_channel_read_timeout(channel,dest,count,is_stderr,timeout);
723 ssh_throw(err);
724 return err;
725 }
726
739 int readNonblocking(void *dest, size_t count, bool is_stderr=false){
740 int err;
741 /* handle int overflow */
742 if(count > 0x7fffffff)
743 count = 0x7fffffff;
744 err=ssh_channel_read_nonblocking(channel,dest,count,is_stderr);
745 ssh_throw(err);
746 return err;
747 }
748 void_throwable requestEnv(const char *name, const char *value){
749 int err=ssh_channel_request_env(channel,name,value);
750 ssh_throw(err);
751 return_throwable;
752 }
753
754 void_throwable requestExec(const char *cmd){
755 int err=ssh_channel_request_exec(channel,cmd);
756 ssh_throw(err);
757 return_throwable;
758 }
759 void_throwable requestPty(const char *term=NULL, int cols=0, int rows=0,
760 const unsigned char* modes=NULL, size_t modes_len=0){
761 int err;
762 if(term != NULL && cols != 0 && rows != 0 && modes != NULL)
763 err=ssh_channel_request_pty_size_modes(channel,term,cols,rows,modes,modes_len);
764 else if(term != NULL && cols != 0 && rows != 0)
765 err=ssh_channel_request_pty_size(channel,term,cols,rows);
766 else
767 err=ssh_channel_request_pty(channel);
768 ssh_throw(err);
769 return_throwable;
770 }
771
772 void_throwable requestShell(){
773 int err=ssh_channel_request_shell(channel);
774 ssh_throw(err);
775 return_throwable;
776 }
777 void_throwable requestSendSignal(const char *signum){
778 int err=ssh_channel_request_send_signal(channel, signum);
779 ssh_throw(err);
780 return_throwable;
781 }
782 void_throwable requestSubsystem(const char *subsystem){
783 int err=ssh_channel_request_subsystem(channel,subsystem);
784 ssh_throw(err);
785 return_throwable;
786 }
799 int requestX11(bool single_connection,
800 const char *protocol, const char *cookie, int screen_number){
801 int err=ssh_channel_request_x11(channel,single_connection,
802 protocol, cookie, screen_number);
803 ssh_throw(err);
804 return err;
805 }
806 void_throwable sendEof(){
807 int err=ssh_channel_send_eof(channel);
808 ssh_throw(err);
809 return_throwable;
810 }
825 int write(const void *data, size_t len, bool is_stderr=false){
826 int ret;
827 if(is_stderr){
828 ret=ssh_channel_write_stderr(channel,data,len);
829 } else {
830 ret=ssh_channel_write(channel,data,len);
831 }
832 ssh_throw(ret);
833 return ret;
834 }
835
836 ssh_session getCSession(){
837 return session->getCSession();
838 }
839
840 ssh_channel getCChannel() {
841 return channel;
842 }
843
844protected:
848 Session *session;
852 ssh_channel channel;
853
854private:
855 Channel (Session &ssh_session, ssh_channel c_channel){
856 this->channel=c_channel;
857 this->session = &ssh_session;
858 }
859 /* No copy and no = operator */
860 Channel(const Channel &);
861 Channel &operator=(const Channel &);
862};
863
864inline Channel *Session::acceptForward(int timeout_ms){
865 ssh_channel forward =
866 ssh_channel_open_forward_port(c_session, timeout_ms, NULL, NULL, NULL);
867 ssh_throw_null(c_session,forward);
868 Channel *newchan = new Channel(*this,forward);
869 return newchan;
870 }
871
872} // namespace ssh
873
875#endif /* LIBSSHPP_HPP_ */
the ssh::Channel class describes the state of an SSH channel.
Definition libsshpp.hpp:523
int read(void *dest, size_t count, bool is_stderr=false, int timeout=-1)
Read data from the channel with optional stderr selection and timeout.
Definition libsshpp.hpp:717
int write(const void *data, size_t len, bool is_stderr=false)
Writes on a channel.
Definition libsshpp.hpp:825
void_throwable close()
closes a channel
Definition libsshpp.hpp:572
bool isClosed()
returns true if channel is in closed state
Definition libsshpp.hpp:600
void_throwable changePtySize(int cols, int rows)
change the size of a pseudoterminal
Definition libsshpp.hpp:561
bool isEof()
returns true if channel is in EOF state
Definition libsshpp.hpp:606
int read(void *dest, size_t count, int timeout)
Read data from the channel with a timeout.
Definition libsshpp.hpp:692
int read(void *dest, size_t count)
Read data from the channel (blocking).
Definition libsshpp.hpp:670
int poll(bool is_stderr=false)
Poll the channel for available data.
Definition libsshpp.hpp:653
int requestX11(bool single_connection, const char *protocol, const char *cookie, int screen_number)
Request X11 forwarding for this channel.
Definition libsshpp.hpp:799
bool isOpen()
returns true if channel is in open state
Definition libsshpp.hpp:612
int openForward(const char *remotehost, int remoteport, const char *sourcehost, int localport=0)
Open a TCP forward channel.
Definition libsshpp.hpp:630
Channel * acceptX11(int timeout_ms)
accept an incoming X11 connection
Definition libsshpp.hpp:547
int readNonblocking(void *dest, size_t count, bool is_stderr=false)
Read data from the channel without blocking.
Definition libsshpp.hpp:739
int getAuthList()
Returns the available authentication methods from the server.
Definition libsshpp.hpp:343
int isServerKnown()
verifies that the server is known
Definition libsshpp.hpp:425
int userauthKbdintGetNPrompts()
Get the number of prompts (questions) the server has given.
Definition libsshpp.hpp:265
int userauthKbdint(const char *username, const char *submethods)
Authenticate through the "keyboard-interactive" method.
Definition libsshpp.hpp:254
void silentDisconnect()
silently disconnect from remote host
Definition libsshpp.hpp:462
void_throwable setOption(enum ssh_options_e type, long int option)
sets an SSH session options
Definition libsshpp.hpp:180
socket_t getSocket()
returns the file descriptor used for the communication
Definition libsshpp.hpp:385
void_throwable setOption(enum ssh_options_e type, void *option)
sets an SSH session options
Definition libsshpp.hpp:193
void_throwable setOption(enum ssh_options_e type, const char *option)
sets an SSH session options
Definition libsshpp.hpp:167
int getVersion()
returns the version of the SSH protocol being used
Definition libsshpp.hpp:415
const char * getDisconnectMessage()
Returns the disconnect message from the server, if any.
Definition libsshpp.hpp:359
int userauthPublickeyAuto(void)
Authenticates automatically using public key.
Definition libsshpp.hpp:216
Channel * acceptForward(int timeout_ms)
accept an incoming forward connection
Definition libsshpp.hpp:864
void_throwable connect()
connects to the remote host
Definition libsshpp.hpp:203
int userauthPublickey(ssh_key privkey)
Authenticates using the publickey method.
Definition libsshpp.hpp:330
int userauthKbdintSetAnswer(unsigned int index, const char *answer)
Set the answer for a question from a message block.
Definition libsshpp.hpp:284
int userauthNone()
Authenticates using the "none" method. Prefer using autopubkey if possible.
Definition libsshpp.hpp:232
std::string getIssueBanner()
gets the Issue banner from the ssh server
Definition libsshpp.hpp:393
int getOpensshVersion()
returns the OpenSSH version (server) if possible
Definition libsshpp.hpp:407
void disconnect()
Disconnects from the SSH server and closes connection.
Definition libsshpp.hpp:351
int userauthPassword(const char *password)
Authenticates using the password method.
Definition libsshpp.hpp:300
void_throwable optionsCopy(const Session &source)
copies options from a session to another
Definition libsshpp.hpp:443
int writeKnownhost()
Writes the known host file with current host key.
Definition libsshpp.hpp:470
void_throwable optionsParseConfig(const char *file)
parses a configuration file for options
Definition libsshpp.hpp:455
int userauthTryPublickey(ssh_key pubkey)
Try to authenticate using the publickey method.
Definition libsshpp.hpp:316
SshException(ssh_session csession)
Construct an exception from a libssh session error state. Captures the current error code and error s...
Definition libsshpp.hpp:85
int getCode()
returns the Error code
Definition libsshpp.hpp:106
std::string getError()
returns the error message of the last exception
Definition libsshpp.hpp:116
SshException(const SshException &e)
Copy-construct an exception.
Definition libsshpp.hpp:94
LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username)
Get available authentication methods from the server.
Definition auth.c:435
LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password)
Try to authenticate by password.
Definition auth.c:1897
LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session, const char *username, const char *passphrase)
Tries to automatically authenticate with public key and "none".
Definition auth.c:1548
LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username)
Try to authenticate through the "none" method.
Definition auth.c:514
LIBSSH_API int ssh_userauth_try_publickey(ssh_session session, const char *username, const ssh_key pubkey)
Try to authenticate with the given public key.
Definition auth.c:723
LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods)
Try to authenticate through the "keyboard-interactive" method.
Definition auth.c:2368
LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i, const char *answer)
Set the answer for a question from a message block.
Definition auth.c:2583
LIBSSH_API int ssh_userauth_publickey(ssh_session session, const char *username, const ssh_key privkey)
Authenticate with public/private key or certificate.
Definition auth.c:865
LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session)
Get the number of prompts (questions) the server has given.
Definition auth.c:2420
LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem)
Request a subsystem (for example "sftp").
Definition channels.c:2200
LIBSSH_API int ssh_channel_send_eof(ssh_channel channel)
Send an end of file on the channel.
Definition channels.c:1400
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr)
Polls a channel for data to read.
Definition channels.c:3338
LIBSSH_API int ssh_channel_get_exit_state(ssh_channel channel, uint32_t *pexit_code, char **pexit_signal, int *pcore_dumped)
Get the exit state of the channel (error code from the executed instruction or signal).
Definition channels.c:3503
LIBSSH_API int ssh_channel_close(ssh_channel channel)
Close a channel.
Definition channels.c:1461
LIBSSH_API int ssh_channel_request_pty_size_modes(ssh_channel channel, const char *term, int cols, int rows, const unsigned char *modes, size_t modes_len)
Request a pty with a specific type and size.
Definition channels.c:2022
LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms)
Reads data from a channel.
Definition channels.c:3167
LIBSSH_API int ssh_channel_request_pty(ssh_channel channel)
Request a PTY.
Definition channels.c:2117
LIBSSH_API int ssh_channel_cancel_forward(ssh_session session, const char *address, int port)
Sends the "cancel-tcpip-forward" global request to ask the server to cancel the tcpip-forward request...
Definition channels.c:2747
LIBSSH_API ssh_channel ssh_channel_open_forward_port(ssh_session session, int timeout_ms, int *destination_port, char **originator, int *originator_port)
Accept an incoming TCP/IP forwarding channel and get information about incoming connection.
Definition channels.c:2728
LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms)
Accept an X11 forwarding channel.
Definition channels.c:2428
LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd)
Run a shell command without an interactive shell.
Definition channels.c:2876
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len)
Blocking write on a channel.
Definition channels.c:1743
LIBSSH_API int ssh_channel_listen_forward(ssh_session session, const char *address, int port, int *bound_port)
Sends the "tcpip-forward" global request to ask the server to begin listening for inbound connections...
Definition channels.c:2638
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value)
Set environment variables.
Definition channels.c:2799
LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel, const void *data, uint32_t len)
Blocking write on a channel stderr.
Definition channels.c:3853
LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum)
Send a signal to remote process (as described in RFC 4254, section 6.9).
Definition channels.c:2942
LIBSSH_API int ssh_channel_is_open(ssh_channel channel)
Check if the channel is open or not.
Definition channels.c:1757
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
Do a nonblocking read on the channel.
Definition channels.c:3277
LIBSSH_API int ssh_channel_is_closed(ssh_channel channel)
Check if the channel is closed or not.
Definition channels.c:1774
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel)
Check if remote has sent an EOF.
Definition channels.c:1789
LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term, int cols, int rows)
Request a PTY with a specific size using current TTY modes.
Definition channels.c:2088
LIBSSH_API void ssh_channel_free(ssh_channel channel)
Close and free a channel.
Definition channels.c:1293
LIBSSH_API ssh_channel ssh_channel_new(ssh_session session)
Allocate a new channel.
Definition channels.c:90
LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol, const char *cookie, int screen_number)
Sends the "x11-req" channel request over an existing session channel.
Definition channels.c:2304
LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost, int remoteport, const char *sourcehost, int localport)
Open a TCP/IP forwarding channel.
Definition channels.c:1156
LIBSSH_API int ssh_channel_request_shell(ssh_channel channel)
Request a shell.
Definition channels.c:2177
LIBSSH_API int ssh_channel_open_session(ssh_channel channel)
Open a session channel (suited for a shell, not TCP forwarding).
Definition channels.c:1089
LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows)
Change the size of the terminal associated to a channel.
Definition channels.c:2137
LIBSSH_API int ssh_get_error_code(void *error)
Retrieve the error code from the last error.
Definition error.c:147
LIBSSH_API const char * ssh_get_error(void *error)
Retrieve the error text message from the last error.
Definition error.c:127
LIBSSH_API int ssh_connect(ssh_session session)
Connect to the ssh server.
Definition client.c:555
LIBSSH_API const char * ssh_get_disconnect_message(ssh_session session)
Get the disconnect message from the server.
Definition session.c:982
LIBSSH_API void ssh_disconnect(ssh_session session)
Disconnect from a session (client or server).
Definition client.c:808
LIBSSH_API char * ssh_get_issue_banner(ssh_session session)
Get the issue banner from the server.
Definition client.c:706
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
This function can set all possible ssh options.
Definition options.c:816
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename)
Parse the ssh config file.
Definition options.c:2342
LIBSSH_API int ssh_get_version(ssh_session session)
Get the protocol version of the session.
Definition session.c:1007
LIBSSH_API int ssh_session_update_known_hosts(ssh_session session)
Adds the currently connected server to the user known_hosts file.
Definition knownhosts.c:1019
LIBSSH_API ssh_session ssh_new(void)
Create a new ssh session.
Definition session.c:64
LIBSSH_API 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.
Definition client.c:733
LIBSSH_API enum ssh_known_hosts_e ssh_session_is_known_server(ssh_session session)
Check if the servers public key for the connected session is known.
Definition knownhosts.c:1350
LIBSSH_API void ssh_silent_disconnect(ssh_session session)
Disconnect impolitely from a remote host by closing the socket.
Definition session.c:620
LIBSSH_API void ssh_free(ssh_session session)
Deallocate a SSH session handle.
Definition session.c:252
LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest)
Duplicate the options of a session structure.
Definition options.c:78
LIBSSH_API socket_t ssh_get_fd(ssh_session session)
Get the fd of a connection.
Definition session.c:720