 |
ewmscp
..
|
Go to the documentation of this file.
4 #include <forward_list>
8 static const std::string
parPrefix(
"libssh");
11 const sftp_statvfs_struct& vfsStat) {
16 aTime = clock_type::time_point(std::chrono::seconds(attrs.atime)
17 + std::chrono::nanoseconds(attrs.atime_nseconds));
18 mTime = clock_type::time_point(std::chrono::seconds(attrs.mtime)
19 + std::chrono::nanoseconds(attrs.mtime_nseconds));
21 mode = attrs.permissions;
27 host(
'\0', optPrefix +
"_host",
28 "host to connect to"),
29 knownHostFile(
'\0', optPrefix +
"_knownHosts",
30 "known hosts file to use"),
31 configFile(
'\0', optPrefix +
"_config",
32 "path to ssh config file"),
33 verbosity(
'\0', optPrefix +
"_verbosity",
34 "libssh verbosity",
"SSH_LOG_NOLOG") {
49 "can't add global known hosts file");
54 *
this,
"set verbosity");
59 #if LIBSSH_VERSION_MINOR > 7
60 switch (ssh_session_is_known_server(
session)) {
61 case SSH_KNOWN_HOSTS_OK:
63 case SSH_KNOWN_HOSTS_CHANGED:
64 throw std::runtime_error(
"host " +
opt.
host +
" key changed");
65 case SSH_KNOWN_HOSTS_OTHER:
66 throw std::runtime_error(
"host " +
opt.
host +
" not found but other key exists");
67 case SSH_KNOWN_HOSTS_NOT_FOUND:
68 throw std::runtime_error(
"known hosts file not found");
69 case SSH_KNOWN_HOSTS_UNKNOWN:
70 throw std::runtime_error(
"host " +
opt.
host +
" is unknown");
71 case SSH_KNOWN_HOSTS_ERROR:
72 throw std::runtime_error(std::string(
"host check error ") + ssh_get_error(
session));
76 "can't verify host ",
opt.
host);
78 if (ssh_userauth_gssapi(
session) != SSH_AUTH_SUCCESS) {
79 if (ssh_userauth_publickey_auto(
session,
nullptr,
nullptr) != SSH_AUTH_SUCCESS) {
80 if (ssh_userauth_agent(
session,
nullptr) != SSH_AUTH_SUCCESS) {
81 throw std::runtime_error(
"can't authenticate at " +
opt.
host);
86 "ssh",
"connect",
"sucessfully authenticated user");
88 "create new sftp session");
101 "ssh",
"reconnect",
"error while reconnecting");
107 "ssh",
"reconnect",
"trying reconnect");
121 auto stat =
getUniquePtr(sftp_lstat(
sftp, path.c_str()), sftp_attributes_free);
122 if (stat ==
nullptr) {
123 if (sftp_get_error(
sftp) == SSH_FX_NO_SUCH_FILE) {
132 sftp_attributes stat;
135 stat = sftp_stat(
sftp, path.c_str());
138 stat = sftp_lstat(
sftp, path.c_str());
140 if (stat ==
nullptr) {
141 if (sftp_get_error(
sftp) == SSH_FX_NO_SUCH_FILE) {
148 sftp_attributes_free(stat);
149 return std::unique_ptr<const genericStat>(retval);
153 static std::map<std::string, sftp_statvfs_struct*> statMap;
154 auto lastSlashAt = path.find_last_of(
'/');
155 if (lastSlashAt == 0) {
156 lastSlashAt = std::string::npos;
158 auto dir = path.substr(0, lastSlashAt);
159 auto item = statMap.find(dir);
160 if (item == statMap.end()) {
162 auto retval = sftp_statvfs(
sftp, dir.c_str());
163 if (retval ==
nullptr) {
164 std::string msg(ssh_get_error(
session));
165 if (msg.find(
"Operation unsupported")) {
166 static sftp_statvfs_struct fakeData;
167 fakeData.f_bsize = 4096;
169 dir,
"statvfs",
"not supported, using fake data");
170 auto result = statMap.emplace(dir, &fakeData);
174 "can't stat fvs for path ", dir);
177 auto result = statMap.emplace(dir, retval);
181 "bsize: ", retval->f_bsize,
182 " frsize:", retval->f_frsize,
183 " blocks:", retval->f_blocks,
184 " bfree:", retval->f_bfree,
185 " bavail:", retval->f_bavail,
186 " files:", retval->f_files,
187 " ffree:", retval->f_ffree,
188 " favail:", retval->f_favail,
189 " fsid:", retval->f_fsid,
190 " flag:", retval->f_flag,
191 " namemax:", retval->f_namemax);
194 return *(item->second);
213 sftp_attributes_free(stat);
214 return std::unique_ptr<const genericStat>(retval);
class for defining the location of a error message in the source code.
virtual void fAddToRange(rangeValueType aValue)
add a value to the range of allowed values
T badval(T call, t badvalue, const Args &... args)
template function to wrap system calls that return a special bad value on failure
bool pathExists(const std::string &path) override
clock_type::time_point mTime
sshOptions(const std::string &optPrefix)
virtual bool fIsSet() const
check if this option was set, regardless of from command line or config file
static const std::string parPrefix("libssh")
std::unique_ptr< const genericStat > getStat() override
clock_type::time_point aTime
genericSftpStat(const sftp_attributes_struct &attrs, const sftp_statvfs_struct &vfsStat)
libsshIoCommon(const std::string &aPath, libsshCommon &aHandler)
options::single< std::string > knownHostFile
T badval(T call, t badvalue, libsshCommon &handler, const Args &... args)
options::single< std::string > verbosity
void emit(level aLogLevel, const location &loc, const std::string &aObject, const std::string &aAction, const Args &... args)
function to create and enqueue a message, this is the only way that messages should be created!
#define timerInst(subfunc)
std::unique_ptr< T, void(*)(T *)> getUniquePtr(T *obj, void(*deleter)(T *))
std::unique_ptr< const genericStat > getStat(const std::string &path, bool followLink) override
options::single< std::string > configFile
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
options::single< std::string > host
T badval(T call, t badvalue, libsshCommon &handler, const Args &... args)
clock_type::duration timeResolution
const sftp_statvfs_struct & getVfsStat(const std::string &path)
T goodval(T call, t goodvalue, libsshCommon &handler, const Args &... args)
void good0(T call, libsshCommon &handler, const Args &... args)
libsshCommon(sshOptions &aOpt)
void good0(T call, libsshCommon &handler, const Args &... args)