Disk ARchive 2.8.0
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
libssh_connection.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 Denis Corbin
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
27
28#ifndef LIBSSH_CONNECTION_HPP
29#define LIBSSH_CONNECTION_HPP
30
31
32#include "../my_config.h"
33
34extern "C"
35{
36#if HAVE_LIBSSH_LIBSSH_H
37#include <libssh/libssh.h>
38#include <libssh/sftp.h>
39#endif
40} // end extern "C"
41
42#include <string>
43
44#include "integers.hpp"
45#include "user_interaction.hpp"
46#include "secu_string.hpp"
47
48namespace libdar
49{
50
53
54
56
57#if LIBSSH_AVAILABLE
58
59 class libssh_connection
60 {
61 public:
62
63 libssh_connection(const std::shared_ptr<user_interaction> & dialog,
64 const std::string & login,
65 const secu_string & password,
66 const std::string & host,
67 const std::string & port,
68 bool auth_from_file,
69 const std::string & sftp_pub_keyfile,
70 const std::string & sftp_prv_keyfile,
71 const std::string & sftp_known_hosts,
72 U_I waiting_time,
73 bool verbose = false);
74
75 libssh_connection(const libssh_connection & ref) = delete;
76 libssh_connection(libssh_connection && ref) = delete;
77 libssh_connection & operator = (const libssh_connection & ref) = delete;
78 libssh_connection & operator = (libssh_connection && ref) = delete;
79 ~libssh_connection() { cleanup_session(); };
80
81 ssh_session & get_ssh_session() { return sess; };
82 sftp_session & get_sftp_session() { return sftp_sess; };
83 U_I get_retry_delay() const { return waiting; };
84 U_I get_max_read() const { return max_read; };
85 U_I get_max_write() const { return max_write; };
86
87 const char* get_sftp_error_msg() const;
88
89 private:
90 ssh_session sess;
91 sftp_session sftp_sess; // this is sftp subsystem handle inside the ssh "sess" session
92 U_I waiting;
93 uint64_t max_read;
94 uint64_t max_write;
95
96
97 void create_session(const std::string & host,
98 const std::string & port,
99 const std::string & login,
100 const std::string sftp_known_hosts,
101 bool verbose,
102 const std::string sftp_pub_keyfile,
103 const std::string & sftp_prv_keyfile);
104
105 void server_authentication(user_interaction & dialog);
106 void user_authentication(user_interaction & dialog,
107 const secu_string & password,
108 bool auth_from_file,
109 const std::string & login,
110 const std::string & host,
111 const std::string & sftp_pub_keyfile,
112 const std::string & sftp_prv_keyfile);
113 void create_sftp_session();
114 void set_max_limits();
115 void cleanup_session();
116
117 static const char* get_key_error_msg(int code);
118 static const char* get_auth_error_msg(int code);
119 };
120
121#endif
122
124
125} // end of namespace
126
127#endif
are defined here basic integer types that tend to be portable
include macro defined by the configure script and some specific additional ones
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
defines the interaction interface between libdar and users.